I have a button click event handler in which i have embedded a javascript code for generating a confirmation box.
Based on the selection in the confirmation box a change is to be made in a hidden field having id hdnField.

In the same btnSubmit_Click() i have a conditional statement written.
Inside the conditional statement i have written a code to make some changes to the page displayed.

All was working fine until I embedde the JavaScript code.
Now after i wrote the script i am facing a problem.
The changes made in the page (which is written inside the conditional statement) is getting displayed only on the second click on the submit button .

Could some one help me to sort this out.
I am pasting the code here.

private void btnSubmit_Click(object sender, System.EventArgs e)
Response.Write("<script language=javascript>alert('Clicked on button submit')</script>");
strJavaScript += "\n<script language='javascript' id='confirmJS'>\n";

strJavaScript += " if(confirm( 'Do you want to continue ? ')) {\n";

strJavaScript += "var objForm = document.forms;\n";

strJavaScript += "var objFormField = objForm.elements;\n";

strJavaScript += " objFormField.value='1';}\n";
strJavaScript +="</script>";
btnSubmit.Enabled = false;
foreach(Control c in PlaceHolder2.Controls)

/* Got some code here which deals with changes to controls inplace Holder

basically you cant create a function from a button click and have it execute on the client, unless you are using Ajax or something like that, because the page_onload event has already fired and therefore you are only writting the function to the page. "The script block added by the RegisterStartupScript method executes when the page finishes loading but before the page's OnLoad event is raised."


I am anot using AJAX .

So how do i introduce a confirmation box on click of the submit button so that the user can hink over whether to submit or not.


in Page_Load why not do something like btnYourButton.Attributes.Add("OnClick","javascript:alert\('hello'\)");

or better would be to use a "return; confirm\('do you really want to do this?'\);"

Thanks a million......... It works!!!!!!! :)