How do I register a server side click on an HTMLGenericControl?
I'm looking for a reliable mechanism to generate a server side postback handler for an HTMLGeneric开发者_如何学JAVAControl such as an li element.
I have some markup that I do not wish to change and would prefer to treat this in the same fashion as a standard .Net server control.
Also, I know I can use a template based control to place some .Net controls within the markup as hidden and then trigger their click events from a client side click proxy. However, I'm really enquiring as to whether this can be done better.
The problem with what you need is:
- there are no server-side control with a valid event handler so that a server-side event can be triggered.
Couple of options I can think of:
- use PageMethods
- call the __doPostBack()
- call a custom javascript to do a XMLHTTP request to the server
Look into the ASP.NET __doPostBack function. Here is a good writeup.
You can add a click handler to your li elements (or whatever) to have them call the __doPostBack function. This is what most other server controls do, so you're using the same mechanism- the only difference would be that you are manually setting the click handler on your elements.
精彩评论