Button in Custom Server Control not firing Click Event
Hello everybody,
I realized a custom server control for an Umbraco-based website.
This control is a form and it contains some buttons in it. For some reason, their click events are not firing.
I put all the initialization in OnInit. It's here that I wrote something like: btnLogin.Click += new EventHandler(btnLogin_Click);
I use IPostBackDataHandler.LoadPostData to retrieve data from the form controls after a post. Inside OnRenderContent I do the actual control rendering (output.Writeline or control.RenderControl(output), etc.).
Can anyone point out what I am doing wrong as I really can't see it?
It will probably be a bit easier to help you out with the code if we can see a snippet of it. :-)
If you have written the onClick event by hand it's possible that there is a typo in it for instance...but I asume that you have used the design view en visual studio and double clicked the button to get the code written for you automatically. So maybe it's the code inside of it that's the problem?
Post a snippet then it will be more easy to help you out.
Yes, of course. I did not mention it, but of course I have created a Macro that invokes my Custom Server Control. The macro is used inside a Master Page, which provides the <form> tag, inside which it is rendered the custom control and it is loaded the Macro by using <umbraco:Macro alias="..." runat="server" />.
Perhaps my question is more generic, perhaps my ideas regarding custom server controls are not that clear...
My objective is to create a custom server control that collects some info from the user, keeps them in mem until the last step is reached and finally persists the information (writes to a db).
Button in Custom Server Control not firing Click Event
Hello everybody,
I realized a custom server control for an Umbraco-based website.
This control is a form and it contains some buttons in it. For some reason, their click events are not firing.
I put all the initialization in OnInit. It's here that I wrote something like: btnLogin.Click += new EventHandler(btnLogin_Click);
I use IPostBackDataHandler.LoadPostData to retrieve data from the form controls after a post. Inside OnRenderContent I do the actual control rendering (output.Writeline or control.RenderControl(output), etc.).
Can anyone point out what I am doing wrong as I really can't see it?
Thanks in advance,
Gianluca
HI Gianluca
It will probably be a bit easier to help you out with the code if we can see a snippet of it. :-)
If you have written the onClick event by hand it's possible that there is a typo in it for instance...but I asume that you have used the design view en visual studio and double clicked the button to get the code written for you automatically. So maybe it's the code inside of it that's the problem?
Post a snippet then it will be more easy to help you out.
/Jan
Hello again!
@Jan: here is the code of my custom server control... thanks for your help!
Cheers, gianluca.
Hi,
I think the macro needs to be enclosed in a <form ruant="server"> tag for it to work. Or did you already try that?
-Tom
Hi Tom,
Yes, of course. I did not mention it, but of course I have created a Macro that invokes my Custom Server Control. The macro is used inside a Master Page, which provides the <form> tag, inside which it is rendered the custom control and it is loaded the Macro by using <umbraco:Macro alias="..." runat="server" />.
Perhaps my question is more generic, perhaps my ideas regarding custom server controls are not that clear...
My objective is to create a custom server control that collects some info from the user, keeps them in mem until the last step is reached and finally persists the information (writes to a db).
I look forward to receiving your opinions,
Cheers,
Gianluca.
is working on a reply...