0

I am using ASP.NET C# Website I have a JavaScript function. In this function, I need to fire a button event. Any suggestions/link?

EDIT

I have a validation function in javascript that i validate on clicking this button. I have a situation, like when i click the button then i need the validation but when I am performing the click(through $("#ID").trigger("click");) then it is not required. Any suggestion?

3
  • How was the event attached to the button? Commented Nov 29, 2011 at 5:10
  • refer this link aspalliance.com/… Commented Nov 29, 2011 at 5:13
  • How did you defined a button ? Is it html or asp.net component ? Commented Nov 29, 2011 at 5:16

2 Answers 2

2
$("#mybutton").trigger("click");  // just fires click event on the button
$("#mybutton").click();           // simulates button click
Sign up to request clarification or add additional context in comments.

2 Comments

...assuming the OP is using jQuery.
I have a validation function in javascript that i validate on clicking this button. I have a situation, like when i click the button then i need the validation but when I performing the click like as suggested by you in above code. then it is not required. Any suggestion?
0

Since you didn't tag as jQuery, I'll assume you're not using it.

If you're setting the event like this:

var someButton = document.getElementById("yourButtonId");
someButton.addEventListener('click', clickEvent);

Then you can raise the click event later like this:

clickEvent();

This also works for me, but I'm not sure how cross-browser safe it is:

var button = document.getElementById("yourButtonId");
button.click();

Comments

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.