You might want to elaborate on what you're trying to do. Response.Write simply adds text to the output stream. You can't "call" anything with it. Are you wanting to create a dynamic javascript function?
apart from the good point from Aidy, i'd like to add a couple of notes.
Response.Write("<script language='javascript'>");
Response.Write("alert('Please enter correct values.');");
Response.Write("return false;");
Response.Write("</script>");
This way you get literal opening brackets in you page! If the problem is you are not in code-behind and the parser gets confused, maybe try this syntax:
Also note that you are not wrapping those javascript statements into a function, so you are actually returning to...?
Finally, about getting started, i'd suggest you try this site's very good tutorial, where you can read about most basic concepts:
http://www.asp.net/quickstart/aspnet/
I would rather use the Required Field Validator like what Aidy said. It is simpler and doesn't require extra code. If you use Javascript, you probably need extra code to put it at the beginning of you the BODY tag.
Also, validator in Asp.net 2.0 has a lot of variation. you can validate phone number and zip code for example.
apart from the good point from Aidy, i'd like to add a couple of notes.
Response.Write("<script language='javascript'>");
Response.Write("alert('Please enter correct values.');");
Response.Write("return false;");
Response.Write("</script>");
This way you get literal opening brackets in you page! If the problem is you are not in code-behind and the parser gets confused, maybe try this syntax:
Also note that you are not wrapping those javascript statements into a function, so you are actually returning to...?
Finally, about getting started, i'd suggest you try this site's very good tutorial, where you can read about most basic concepts:
http://www.asp.net/quickstart/aspnet/
HTH. -LV
The bolded/italic format worked fine for me. Thanks
harish_s
Member
20 Points
4 Posts
How to call Javascript function using Response.Write()
Jun 16, 2006 12:25 PM|LINK
Hi all there, [:)]
Its Harish a newbee to this forum. I want to call a javascript within code behind using Response.Write. How can i achieve this.
Plz help.
Thanx in advance.
Regards
harry
Harry
--Happy Programming--
Aidy
Contributor
3585 Points
711 Posts
Re: How to call Javascript function using Response.Write()
Jun 16, 2006 02:16 PM|LINK
harish_s
Member
20 Points
4 Posts
Re: How to call Javascript function using Response.Write()
Jun 16, 2006 02:22 PM|LINK
thanx for reply,
yes i want to create dynamic javascript function, which will restrict user to post the form unless and untill the fields are filled correctly.
Response.Write("<script language='javascript'>"); Response.Write("alert('Please enter correct values.');"); Response.Write("return false;"); Response.Write("</script>");if i do such thing like above code with returning false, it display the alert message but then there is no content left for the page.
plz help.
thanx in advance
regards,
harry
Harry
--Happy Programming--
Aidy
Contributor
3585 Points
711 Posts
Re: How to call Javascript function using Response.Write()
Jun 16, 2006 02:30 PM|LINK
LudovicoVan
Star
9692 Points
1935 Posts
Re: How to call Javascript function using Response.Write()
Jun 16, 2006 05:32 PM|LINK
Hello harish_s,
apart from the good point from Aidy, i'd like to add a couple of notes.
Response.Write("<script language='javascript'>");
Response.Write("alert('Please enter correct values.');");
Response.Write("return false;");
Response.Write("</script>");
This way you get literal opening brackets in you page! If the problem is you are not in code-behind and the parser gets confused, maybe try this syntax:
Response.Write("<script language='javascript'>");
Response.Write("alert('Please enter correct values.');");
Response.Write("return false;");
Response.Write("<" + "/script>");
Also note that you are not wrapping those javascript statements into a function, so you are actually returning to...?
Finally, about getting started, i'd suggest you try this site's very good tutorial, where you can read about most basic concepts: http://www.asp.net/quickstart/aspnet/
HTH. -LV
iloveny
Participant
1534 Points
336 Posts
Re: How to call Javascript function using Response.Write()
Jun 16, 2006 08:12 PM|LINK
Also, validator in Asp.net 2.0 has a lot of variation. you can validate phone number and zip code for example.
harish_s
Member
20 Points
4 Posts
Re: How to call Javascript function using Response.Write()
Jul 06, 2006 11:38 AM|LINK
Hi there,
thanx alot guys for such a wonder ful help, anyways it worked out for me. thanx alot.
regards,
harry
Harry
--Happy Programming--
rkeslar
Participant
853 Points
900 Posts
Re: How to call Javascript function using Response.Write()
Aug 01, 2012 09:12 PM|LINK
The bolded/italic format worked fine for me. Thanks