Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 1st, 2007, 05:02 PM
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">
    <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!!



Reply With Quote
  #2 (permalink)  
Old January 1st, 2007, 05:11 PM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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>


Reply With Quote
  #3 (permalink)  
Old January 1st, 2007, 05:25 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.
Reply With Quote
  #4 (permalink)  
Old January 1st, 2007, 06:30 PM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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!


Reply With Quote
  #5 (permalink)  
Old January 1st, 2007, 09:35 PM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.




Reply With Quote
  #6 (permalink)  
Old January 2nd, 2007, 04:36 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.
Reply With Quote
  #7 (permalink)  
Old January 2nd, 2007, 02:06 PM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #8 (permalink)  
Old January 2nd, 2007, 03:17 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.
Reply With Quote
  #9 (permalink)  
Old January 9th, 2007, 03:09 PM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #10 (permalink)  
Old January 9th, 2007, 04:12 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
post back SKhna ASP.NET 2.0 Basics 1 March 10th, 2008 09:23 AM
post back k.manisha ASP.NET 1.0 and 1.1 Professional 2 February 7th, 2007 02:28 PM
Post Back rngrmn Pro VB.NET 2002/2003 1 May 5th, 2006 11:21 AM
Post Back rngrmn VB.NET 2002/2003 Basics 2 April 6th, 2006 01:14 PM



All times are GMT -4. The time now is 08:00 AM.


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