I have a ASP.NET button but recently, I replaced it with a standard HTML button ... What I need to do is a postback to an ASP.NET page and ensure a method is called.
The previous button was an ASP.NET button, so I had this event:
Protected Sub btnCancelar_Click(ByVal sender As Object, ByVal e As System.EventArgs)
UtilTMP.DisposeObjects()
Server.Transfer("~\Forms\test.aspx", True)
End
But I was using a button with a JavaScript ALERT and I recently changed to a jQuery UI Modal dialog but it doesn't wait for me to answer the question.. the postback happenes immediatly ... so I decided to change to a standard HTML button ... but I need to postback to the ASP.NET page and call a method like.
If I just postback it won't call the cleanup
Protected Sub Cleanup()
UtilTMP.DisposeObjects()
Server.Transfer("~\Forms\test.aspx", True)
End
Learning jQuery "PostBack is the name given to the process of submitting an ASP.NET page to the server for processing .". Once there is a postback (on click of button) that particular code should never ever get called again.
How to Raise a Postback from JavaScript? To do this, we need to just call the __doPostBack() function from our javascript code. When the above function is called, it will raise a postback to server.
A postback is the exchange of information between servers to report a user's action on a website, network, or app.
See if this helps: http://www.codeproject.com/KB/aspnet/sample.aspx.
Basically, you declare a dummy anchor tag:
<a id="anchorId" runat="server" onclick="return true" onserverclick="foo"></a>
In your code behind, you need to declare a foo method:
protected void foo(object sender, EventArgs e)
{
// Do something here
}
Then you can invoke this anchor's onclick function with this javascript:
document.getElementById('anchorId').click()
While you can do Postbacks with JQuery, it might be better to call a web method (web service that is in your page). The call could also be faster because you are not posting the entire page ViewState.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With