•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 391,552 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,581 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 2156 | Replies: 4
![]() |
•
•
Join Date: Feb 2007
Posts: 13
Reputation:
Rep Power: 2
Solved Threads: 0
Hi,
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.
privatevoid 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['Form1'];\n";
strJavaScript += "var objFormField = objForm.elements['hdnField'];\n";
strJavaScript += " objFormField.value='1';}\n";
strJavaScript +="</script>";
this.RegisterStartupScript("confirmJS",strJavaScript);
Response.Write(hdnField.Value.ToString());
if(hdnField.Value.Equals(1.ToString()))
{
btnSubmit.Enabled = false;
if(PlaceHolder2.HasControls())
{
foreach(Control c in PlaceHolder2.Controls)
{
/* Got some code here which deals with changes to controls inplace Holder
}
}
}
}
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.
privatevoid 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['Form1'];\n";
strJavaScript += "var objFormField = objForm.elements['hdnField'];\n";
strJavaScript += " objFormField.value='1';}\n";
strJavaScript +="</script>";
this.RegisterStartupScript("confirmJS",strJavaScript);
Response.Write(hdnField.Value.ToString());
if(hdnField.Value.Equals(1.ToString()))
{
btnSubmit.Enabled = false;
if(PlaceHolder2.HasControls())
{
foreach(Control c in PlaceHolder2.Controls)
{
/* Got some code here which deals with changes to controls inplace Holder
}
}
}
}
•
•
Join Date: Jan 2007
Location: Japan
Posts: 70
Reputation:
Rep Power: 2
Solved Threads: 4
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."
sedgey: so little daylight, too much caffeine
MCSD MCAD MCSE
http://www.thefriendlybuilder.co.uk,
http://www.sheetmusicdirect.com
MCSD MCAD MCSE
http://www.thefriendlybuilder.co.uk,
http://www.sheetmusicdirect.com
•
•
Join Date: Jan 2007
Location: Japan
Posts: 70
Reputation:
Rep Power: 2
Solved Threads: 4
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?'\);"
or better would be to use a "return; confirm\('do you really want to do this?'\);"
Last edited by sedgey : Feb 8th, 2007 at 10:24 pm.
sedgey: so little daylight, too much caffeine
MCSD MCAD MCSE
http://www.thefriendlybuilder.co.uk,
http://www.sheetmusicdirect.com
MCSD MCAD MCSE
http://www.thefriendlybuilder.co.uk,
http://www.sheetmusicdirect.com
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
- Calling a javascript function from C# (C#)
- I have a link wich opens a the second page with links wich call a javascript functio (JavaScript / DHTML / AJAX)
- how to extract data from javascript into php (PHP)
- Can anyone please help my problem...? (JavaScript / DHTML / AJAX)
Other Threads in the ASP.NET Forum
- Previous Thread: Vb.net save html to file
- Next Thread: listbox multiple selection


Linear Mode