开发者

asp disable button postback

开发者 https://www.devze.com 2023-01-17 06:53 出处:网络
i\'m working on a web page with a lot of jquery animation on the page load. I also have a contact form, with the \"send\" button that sends the form data to the clients email.

i'm working on a web page with a lot of jquery animation on the page load. I also have a contact form, with the "send" button that sends the form data to the clients email. Now, when i press the button, the page posts back and loads (incl the animation at the begining) again.. and i don't want that.. I saw some solutions on the net that require to put the "return false" in the onClientClick attribute, but that disables the code behind in c# to be executed, thus disables the form data to be sant to the desired email.

the code is preety simple

<asp:Button ID="sendButton" runat="server" Text="Send" onclick="sendButton_Click" />

and in the sendButton_Click method in the code behind i have 开发者_JS百科the logic to send the data...

Any help would be appriciated!


Your problem is probably not to stop the postback of your button, but somehow adjust your jQuery animation s.t. it isn't repeated once the page posts back.

A possibility to handle this may be to place server tags in your jQuery script like

if(<%=!Page.IsPostBack %>){
   //do jQuery animation
}

With some adjustments this could work. You have to check what exactly "Page.IsPostBack" returns you. Maybe you get the result as String s.t. you have to compare it explicitly in your JavaScript.


try this:

protected void Page_Load( object sender, EventArgs e )
{
       if ( !Page.IsPostBack )
       {
           myButton.Attributes["onclick"] = "this.removeAttribute('onclick');" + Page.ClientScript.GetPostBackEventReference( myButton, null );
       }
}


tnx for the anwsers everybody, but i've come up with a solution myself... i put the contact content in an iframe, and when the user clicks the button, only the iframe posts back - not the main page..


Just send the form back using AJAX.

http://api.jquery.com/category/ajax/

0

精彩评论

暂无评论...
验证码 换一张
取 消