Register javascript in codebehind is not working
Hi friends,
I am using Asp.Net application. From my codebehind i call the javascript function. so i am using,
Page.ClientScript.RegisterStartupScript(Me.GetType(), "onLoad", "showcontent()", True)
Now i registered script.Now i call the function showcontent in my contentpage.
<script type="text/javascript" language="javascript">
//window.onLoad=showcontent();
function showcontent()
{
alert("enter");
}
while my contentpage load, this script fire and give alert message.But it doesn't fire.It gives script error. ie
"missing ;before statement.[Break on this error] showcontent()Sys.Application.initialize();\n
This error is happened in firefox. Run in IE nothing happened. The script is not fired in IE. what is the problem? I cant find it.
Please help me if u can.
Hope ur's reply
Thanks
:)
Re: Register javascript in codebehind is not working
I can't see any reason why it isn't working. I'm assuming the missing closing tag </script> is just a typo or wasn't copied over.
Where are you placing the javascript in your .aspx page and where are you calling RegisterStartupScript in your codebehind?
Re: Register javascript in codebehind is not working
showcontent()
should be
showcontent();
Re: Register javascript in codebehind is not working
s mendhak. Its right. I missed semicolon.
Re: Register javascript in codebehind is not working
Add Resolved, you know the drill ;)
Re: Register javascript in codebehind is not working
Page.ClientScript.RegisterStartupScript(Me.GetType(), "onLoad1", "DisplayDivTwo();", True)
In the code First i didnt put semicolon DisplayDivTwo(). I Put DisplayDivTwo(); . I put now. It's working.
But i got another problem now mendhak.
ie., window.location="frmContentPageOne.aspx" It goes to this page while page load in firefox.But in IE its not working.
I change the script window.location.href="frmContentPageOne.aspx". But it doesn't working.
Hopes ur's reply.
Re: Register javascript in codebehind is not working
It's single quote and a semicolon
window.location.href='pagename.aspx';