michael1174
asked on
Confirmation box using javascript and C# ASP.NET
Can someone help me get this confirmation box to work in javascript and c#? Right now its refreshing the page. I am putting it on my page load event. Also, can someon give me an example using this same code to instead of redirecting the user to another page to execute a function instead. Thanks!
string MessageToDisplay = "Do you want to exit?";
btnExit.Attributes.Add("on Click", "javascript:if(!confirm('" + MessageToDisplay + "')) window.location='Search.as px'");
string MessageToDisplay = "Do you want to exit?";
btnExit.Attributes.Add("on
btnExit.Attributes.Add("on Click", "if(!confirm('" + MessageToDisplay + "')) window.location='Search.as px'; return false");
ASKER
mplugjan, try this but it keeps refreshing the page...
I have my btnExit defined as:
protected System.Web.UI.WebControls. Button btnExit;
I have my btnExit defined as:
protected System.Web.UI.WebControls.
1. It should be
Add("onClick", "if(!confirm('" + MessageToDisplay + "')) { window.location='Search.as px'; return false }");
Is btnExit a submit button?
If so, you need to return false on the onSubmit instead
Then I suggest whatever it takes to get the form to do
.....Add("onSubmit", "if(!confirm('" + MessageToDisplay + "')) { window.location='Search.as px'; return false }");
Add("onClick", "if(!confirm('" + MessageToDisplay + "')) { window.location='Search.as
Is btnExit a submit button?
If so, you need to return false on the onSubmit instead
Then I suggest whatever it takes to get the form to do
.....Add("onSubmit", "if(!confirm('" + MessageToDisplay + "')) { window.location='Search.as
ASKER
Its not a submit button... i used your
Add("onClick", "if(!confirm('" + MessageToDisplay + "')) { window.location='Search.as px'; return false }");
but its doing to opposite of what I expected.. cancel goes to the search page, OK says on the page.
Add("onClick", "if(!confirm('" + MessageToDisplay + "')) { window.location='Search.as
but its doing to opposite of what I expected.. cancel goes to the search page, OK says on the page.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok, thanks... one other thing... instead of redirecting to another page, how do i call a c# function called AddCoverages in javascript?
basically want to accomplish this:
Add("onClick", "if(confirm('" + MessageToDisplay + "')) { call AddCoverages; return false }");
basically want to accomplish this:
Add("onClick", "if(confirm('" + MessageToDisplay + "')) { call AddCoverages; return false }");
I have no idea unless it involves submitting the form
Here is a tutorial in how to postback from javascript
http://www.dotnetspider.com/kb/Article1939.aspx
Here is a tutorial in how to postback from javascript
http://www.dotnetspider.com/kb/Article1939.aspx