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?

1
  • 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? Commented Apr 15, 2011 at 14:15

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Awesome, this looks pretty cool, thanks for your comprehensive answer, will give it a shot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.