开发者

How can I link a html button to a codebehind method in asp.net?

I h开发者_JAVA百科ave a JQueryTemplate that renders some number of textboxes and corresponding submit buttons. How do I handle the click method of the button? Is there also a way to identify which button was pressed? Each template textbox/button pair has an ID associated with it.

Ideally I would like to simply have a templateButton_click() method and be able to extract the ID and value of the textbox from it. Could someone point me in the right direction?


__doPostBack on the client side is probably what you're after: How to use __doPostBack()


To call a server side method on a client side event you need to do the following:

1- Create the server side method that do whatever you want to do when the client event occured:

templateButton_click(string textBoxID)

2- Implement the RaisePostBackEvent event handler which take one string argument (That will be the ID of the related TextBox). Call your defined method in it:

public void RaisePostBackEvent(StringeventArgument) : System.Web.UI.IPostBackEventHandler.RaisePostBackEvent        
{
    templateButton_click(eventArgument)
}

3- Write a script to trigger post back action:

function TriggerPostBack(control, arg){    
    __doPostBack(control, arg);
}

4- Call the PostBack trigger function on the click event of each button and specify the realted TextBox ID as an argument :

<button .... onclick="TriggerPostBack('ButtonID', 'RealatedTextBoxID')" .. />
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜