Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 23, 2008 02:12 PM by talha83
0 Points
25 Posts
Feb 22, 2008 11:09 AM|LINK
hi,
i want to run a javascript on pageload. The page is actually included in a master page. the script is in the content place holder.
eg.
aaa.aspx
========
<
obj1=(document.all) ? document.all[
obj1.style.display=(obj1.style.display==
</
the script which is written is supposed to be executed when this aaa.aspx page gets loaded. how to run the script??
ASP.NET 2.0
Participant
1242 Points
240 Posts
Feb 22, 2008 01:06 PM|LINK
Since it's not a function, it should get executed by itself.
Feb 22, 2008 01:08 PM|LINK
Also, for your learning, if it was a function like this: <script> function ShowAlert() { alert ('test'); } </script>
in your page_load, you would write this script to run it: Literal l = new Literal(); l.Text = "<script>ShowAlert();</script>"; this.Controls.Add(l);
All-Star
82577 Points
15430 Posts
MVP
Feb 22, 2008 01:33 PM|LINK
Try adding this to your HTML after the controls are declared.
<script type="text/JavaScript"> <!-- window.onload = function () { // Your code goes here... }; // --> </script>
NC...
Feb 23, 2008 10:32 AM|LINK
thanks very much. that solved my problem.
asp.net2.0
Feb 23, 2008 02:12 PM|LINK
Mark it as answered please.
sanju baba
0 Points
25 Posts
want to run a javascript on page load
Feb 22, 2008 11:09 AM|LINK
hi,
i want to run a javascript on pageload. The page is actually included in a master page. the script is in the content place holder.
eg.
aaa.aspx
========
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"><
script language="javascript" type="text/javascript"> obj=(document.all) ? document.all['<%=pnlOptPro.ClientID %>'] : document.getElementById('<%=pnlOptPro.ClientID %>');obj.style.display=(obj.style.display=='none') ? 'inline' : 'none';obj1=(document.all) ? document.all[
'<%=pnlUsrwise.ClientID %>'] : document.getElementById('<%=pnlUsrwise.ClientID %>');obj1.style.display=(obj1.style.display==
'none') ? 'inline' : 'none'; </script></
asp:Content>the script which is written is supposed to be executed when this aaa.aspx page gets loaded. how to run the script??
ASP.NET 2.0
talha83
Participant
1242 Points
240 Posts
Re: want to run a javascript on page load
Feb 22, 2008 01:06 PM|LINK
Since it's not a function, it should get executed by itself.
MCP, MCAD, MCPD
Personal Blog
talha83
Participant
1242 Points
240 Posts
Re: want to run a javascript on page load
Feb 22, 2008 01:08 PM|LINK
Also, for your learning, if it was a function like this:
<script>
function ShowAlert()
{
alert ('test');
}
</script>
in your page_load, you would write this script to run it:
Literal l = new Literal();
l.Text = "<script>ShowAlert();</script>";
this.Controls.Add(l);
MCP, MCAD, MCPD
Personal Blog
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: want to run a javascript on page load
Feb 22, 2008 01:33 PM|LINK
Try adding this to your HTML after the controls are declared.
<script type="text/JavaScript">
<!--
window.onload = function ()
{
// Your code goes here...
};
// -->
</script>
NC...
sanju baba
0 Points
25 Posts
Re: want to run a javascript on page load
Feb 23, 2008 10:32 AM|LINK
hi,
thanks very much. that solved my problem.
asp.net2.0
talha83
Participant
1242 Points
240 Posts
Re: want to run a javascript on page load
Feb 23, 2008 02:12 PM|LINK
Mark it as answered please.
MCP, MCAD, MCPD
Personal Blog