call code behind event if clicking on a non-server control hyperlink?
If you have a standard hyperlink...
<a href="somelink"> message </a>开发者_高级运维;
...and this link is not inside a form runat="server" tag, and you can't put it inside one, either, would you know of any possible way to tie the click event for this tag to a code-behind method?
To call a server side method on a client side event you need to do the following:
1- Create the server side method:
void DoSomething(...) { ... }
2- Implement the System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
which take one string argument (You can assign the name to the value of this argument).:
public void RaisePostBackEvent(string eventArgument)
{
DoSomething(...);
}
3- Write a script to trigger post back:
function TriggerPostBack(control, arg){
__doPostBack(control, arg);
}
4- Call the PostBack trigger function when needed:
<a .... onclick="TriggerPostBack('control', 'arg')" .. />
精彩评论