 |
| ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 5th, 2006, 09:37 AM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
I have tried that one too.In both the cases(the one i sent you before and this one) when i click the button the pop up does come up although it doesnt do anything even if i click "ok" to it.What i am trying to do is not to get that pop up at all when i click the submit button.
Here is HTML for that one.
*****************
<HTML><HEAD><title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"content="http://schemas.microsoft.com/intellisense/ie5">
<script language="JavaScript">
var needToConfirm = true;
window.onbeforeunload = confirmExit;
function confirmExit()
{
if (needToConfirm)
return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?";
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form name="Form1" method="post" action="WebForm1.aspx" id="Form1">
<input type="hidden" name="__VIEWSTATE" value="dDw5NjU1MTU1Ozs+ZMe/YzNJ8mHHmvf5Yc5QSvBQljk=" />
<input type="submit" name="Button1" value="Button" id="Button1" OnClientClick="needToConfirm=false; return true;" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" />
</form>
</body>
</HTML>
***************************************
Thanks a lot
Kamal
|
|

December 5th, 2006, 09:44 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Right I think I know what's going on. You posted this in an ASP.NET 2 forum, but your question is related to ASP.NET 1.x, right?
OnClientClick is new in ASP.NET 2 so you can't use it.
Instead, add the attribute in the page's Load event, like this:
Code:
protected void Page_Load(object sender, EventArgs e)
{
Button1.Attributes.Add("onclick", "needToConfirm=false; return true;");
}
You can then remove the line with document.all["Button1"]..... from your code and it should work.
Cheers,
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.
|
|

December 5th, 2006, 09:49 AM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar
This is awesome.You are too good.Its working fine in this dummy one but i have to replicate this thing in actual application and will write back to tell you.Also you were right about me being stupid enough to post this in ASP.Net2.0 when i was working in 1.1.But ia m so impressed.
Thanks a ton for your help
Kamal
|
|

December 5th, 2006, 10:33 AM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hey Imar,
Your code is playing its magic in my application.Thanks a lot.I was working on this for 4 days now and was almost on verge of giving up.
I have still one question.Is there a way to customize the message that pop up displays?
Thanks
Kamal
|
|

December 5th, 2006, 10:44 AM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
Right now my java script function looks like this
*****************
function confirmExit()
{
if (needToConfirm)
return "Do you want to close the screen without posting the items?Select OK to close and Cancel to ";
}
************************
But the message it displays on pop up is
"Are you sure you want to navigate away from this page?Do you want to close the screen without posting the items?Select OK to close and Cancel to.
Pree Ok to continue and Cancel to stay on current page."
**************************
I want to change this message to just one different line.Is this possible?And if yes how?
Thanks
Kamal
|
|

December 5th, 2006, 06:48 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I could be wrong, but I don't think you can. Looking at the message, I think this is something created by the browser.
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.
|
|

December 5th, 2006, 11:52 PM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar
So you mean even if i use something like
return=confirm("Do you want to exit?");
*****
It would still return the message like
"You are navigating away from this screen.Do you want to exit?"
Thanks
Kamal
|
|

December 6th, 2006, 02:58 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yes, I think so. This is a browser security setting to stop pages from redirecting you away without your approval.
There may be ways to work around this, but I don't know them...
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.
|
|
 |