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 b开发者_如何学JAVAutton click on a asp button and i am wondering how i would do this?
Thanks in advance.
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. });
Consider using the WatiN framework. It allows browser ui automation easily.
Example:
browser.Button(Find.ByName("<buttonname>")).Click();
Alternatively, you could use ClientScriptManager.RegisterStartupScript()
to call client script from code-behind.
精彩评论