p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   General .NET (http://p2p.wrox.com/forumdisplay.php?f=122)
-   -   Why does the form always post back? (http://p2p.wrox.com/showthread.php?t=52108)

Conch January 1st, 2007 05:02 PM

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">
    <div>
      <asp:Button ID="Button1" runat="server" Text="Click Me" />
      <br />
      <asp:Label ID="Label1" runat="server"></asp:Label>&nbsp;</div>
    </form>

   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');")
      Else
         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!!




Conch January 1st, 2007 05:11 PM

This is the source view for the page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
    Untitled Page
</title></head>
<body>
    <form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTMyNDcxODYzNQ9kFgICAw9kFgQCAQ8PZBYCHgdvbmN saWNrBR9yZXR1cm4gY29uZmlybSgnQXJlIHlvdSBzdXJlJyk7Z AIDDw8WAh4EVGV4dAULd2UgYXJlIGhlcmVkZGSQ/Oq3Drv2Pc4+BrqqUfLCyPgCQg==" />
</div>

    <div>
      <input type="submit" name="Button1" value="Click Me" onclick="return confirm('Are you sure');" id="Button1" />
      <br />
      <span id="Label1">Page Post Back</span>&nbsp;</div>

<div>

    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgLA/tiqCAKM54rGBr+u5KLu5GZgThB0vAyEeVkVD1XA" />
</div></form>
</body>
</html>



Imar January 1st, 2007 05:25 PM

To be honest, I have no idea. This is how it's supposed to look.

Are you having problems with JavaScript in other sites as well? Did you change any of the Script settings in the IE Options dialog?

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.

Conch January 1st, 2007 06:30 PM

At first I runned into this problem when I tried to add confirm diaglog box with a linkbutton in the gridview control.
I found that the record in the Gridview was always deleted even if I clicked Cancel button.
Later, I made this code to test to make clear this problem. I found that the result was the same as the gridview.

I didn't change any Script settings in the IE options dialog. Maybe the default setting of the IE in my computer(this is a new lap top) is wrong.
Could you tell me What the script setting or other enviroment setting should be to let IE browser care about client script?
Or what reference I could get to check my computer environment setting is correct to run a website with client site?

Thanks a lot for your help!



Conch January 1st, 2007 09:35 PM

I want to know that

   How does the IE browser work for a website with javascript behind scene?

Suppose the browser gets a FALSE value from javascript, it stops submitting the form.
How does it work behind scene. Does it need to check some setting in the environment? If it is, what should be?

Right now, javascript can render a CORRECT value(false from cancel button). That means javascript setting should be right.
The problem is that the IE browser doesn't care the value from javascript, and continuely submit the form.





Imar January 2nd, 2007 04:36 AM

I think you should ask Bill if you want to know what happens exactly... ;)

However, what it comes down to when you click Cancel is this:

<input type="submit" onclick="return false;" />

Because the onclick handler returns false, the button will no longer submit to the server.

This has always worked for me, and is how it should be. If it doesn't work for you, something very odd is going on....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.

Conch January 2nd, 2007 02:06 PM

I tried the code and got the same result. The browser couldn't halt submitting the form even it got FALSE.

So, I believe that some weird things happended in my computer.


Imar January 2nd, 2007 03:17 PM

Yeah, it looks like that.....

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.

Conch January 9th, 2007 03:09 PM

I have solved my problem.

The Browser Helper Object in the FlashGet interferes with the normal operation of the IE browser.

I disabled the FlashGetBHO in the Manage Add-on of IE tools. The page worked!!


Conch


Imar January 9th, 2007 04:12 PM

Great! Thanks for the update...

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.


All times are GMT -4. The time now is 07:09 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.