Click to See Complete Forum and Search --> : how to use javascript code in between C# Code?


veerabhadra
October 12th, 2006, 03:11 AM
How to use return value of javacript alert function when we use in C# by RegisterStartupScript.

This is my code:
string scriptString = "<script language='javascript'>" +
"confirm("are u sure to book this?");</script>";
Page.RegisterStartupScript("ScriptString ", scriptString );

I want to use return value of that alert i.e i user click yes iwant to do something. if No some other thing

can i use that return value:if yes how to use that?Is ther modifications in the to scriptString use the return value?

jasonli
October 12th, 2006, 08:41 AM
You could change the script a little, like:

string scriptString = "<script language='javascript'>" +
"return confirm("are u sure to book this?");</script>";

HairyMonkeyMan
October 12th, 2006, 08:54 AM
If you are wanting to execute code in a button event when the user clicks ok, or do nothing when they click cancel - try this - put it in the page_load routine:

btnButtonName.Attributes.Add("onclick", "return confirm('are u sure to book this?')");

Have fun :D

bravey9
October 13th, 2006, 10:59 PM
And you can also refer to this nice and simple article in code guru itself..
http://www.codeguru.com/Csharp/.NET/net_asp/scripting/article.php/c5337/