3

I have 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?

NibblyPig
  • 51,118
  • 72
  • 200
  • 356
  • Are you looking to post back to the server or make an AJAX call or simply execute some client-side script when those submit buttons are clicked? – George Apr 15 '11 at 14:15

2 Answers2

2

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

Community
  • 1
  • 1
Shan Plourde
  • 8,528
  • 2
  • 29
  • 42
2

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')" .. />
Akram Shahda
  • 14,655
  • 4
  • 45
  • 65