View Single Post
  #1 (permalink)  
Old January 1st, 2007, 05:02 PM
Conch Conch is offline
Registered User
Join Date: Jan 2007
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Why does the form always post back?

How does let the browser of IE to care about the value returned from the client script?(that is the exact subject, too long to fit the Subject box)

     I met a problem is about confirm diaglog box added on a button. No matter I clicked OK or Cancel, even I clicked X to close the pop up dialog, the page always post back.
      I used web visual developer 2005 express (VB). The code I used to test was as follow.
    <form id="form1" runat="server">
      <asp:Button ID="Button1" runat="server" Text="Click Me" />
      <br />
      <asp:Label ID="Label1" runat="server"></asp:Label>&nbsp;</div>

   code bind:

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

      If Not Page.IsPostBack Then
         Button1.Attributes.Add("onclick", "return confirm('Are you sure');")
         Label1.Text = "Page post back."
      End If

    End Sub

    After tested in IE 6.0, I am sure that the confirm diaglog did the right job. It returned the False value if I clicked Cancel button. But the browser doesn't care about the return value from script, continutely submit the form.
    Later, I tested the code in the FireFox, it worked.

 So What's wrong with the IE browser? Is there a setting problem?

I really appreciate your help!!

Reply With Quote