开发者

call code behind event if clicking on a non-server control hyperlink?

开发者 https://www.devze.com 2023-03-12 20:33 出处:网络
If you have a standard hyperlink... <a href=\"somelink\"> message </a>开发者_高级运维;

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')" .. /> 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号