views:

29

answers:

4

Hi, 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 the logic to send the data...

Any help would be appriciated!

A: 

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.

Juri
A: 

try this:

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

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..

Andrej
:O sounds hacky
Juri
A: 

Just send the form back using AJAX.

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

gil