1

I have a hidden button on my page which fires a jquery function, seen as though i cant call the jquery function from the server side im trying to fire the button click on a asp button and i am wondering how i would do this?

Thanks in advance.

1
  • To clarify, you want jquery to trigger a postback event to the server? Commented Jun 22, 2011 at 13:52

3 Answers 3

2

I'm not entirely sure what it is you want to do, but here are a couple of options:

For simulating a click on an HTML button (clientside), you could use JQuery:

$("#mybutton).click();

or

$("#mybutton).trigger("click");  

Of course you'll need to attach the handler to the button in your

$(document).ready(function(){
    $("#mybutton").click(function(){
        //do something
    });
});

If you want to simulate a click on an ASP.Net (serverside button):

You can simulate a button being clicked by calling the function the button's Click event is bound to:

<asp:button runat="server" id="btn1" Onclick="btn1_Click" Text="Click Me" />

protected void btn1_Click(object sender, EventArgs e){
    //stuff that happens when you click the button.
}

and then in code:

e.g.

btn1_Click(null, new EventArgs());

Responses to an earlier question go into more depth on this subject.

UPDATE:

From the serverside the best you could do is reload the page and then get it to generate a script to make the necessary function calls.

Does the button have to be an or can it be a regular HTML button? If the latter just wire it up to a function that makes the call to modal by its Id.

If the former, you'll need to add a CssClass to the declaration and wire it up to a function via its class - $(document).ready(function(){ $(".myButtonClass").click(function(){//Wired-up by class $("#myButtonId").click(function(){//Wired-up by html ID $('#MyModalContent').modal(); return false; //you might need extra code to prevent the event propogating. });

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

3 Comments

ok so when the button clicks it fires <asp:Button ID="Button2" runat="server" class="osx" Text="Click" /> which then display a popup window i cant think of a way to fire this jquery from the server side so i was trying to mimic the server firing the button but also because i have a formRewriter which enables me to do things like Default.aspx?Profile=PROFILEID which fires every time any post back is done then i dont think what im trying to do is possible :/
if you want to display an alert box (client side) you should just wire up the client-side event of the HTML button with Jquery or vanilla JS. If you can post some markup it will make it easier for us StackOverflowers to understand your requirements.
the popup box is one used here ericmmartin.com/projects/simplemodal-demos it is the osx style i want to be able to fire the popup from the server side
1

Consider using the WatiN framework. It allows browser ui automation easily.

Example:

browser.Button(Find.ByName("<buttonname>")).Click();

Comments

0

Alternatively, you could use ClientScriptManager.RegisterStartupScript() to call client script from code-behind.

1 Comment

how can i use this to fire a function that is fired by a buttons class name? ie the buttons class name is OSX and it then fires the jQuery

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.