Reputation: 3427
I need a javascript function to fire when my aspx page has loaded. The problem is it's in a master page. If I put the code in the onload of the master page then it tries to fire for every page that uses the master page. I only want it to happen for one specific page. If I put it in the Content placeholder it doesn't work. The control isn't loaded yet. I tried putting it at the bottom of the content placeholder and that didn't work either. So I need it to happen in an onLoad event but one that only fires for this specific page and not every page that uses the master page.
Please, no jQuery.
Upvotes: 2
Views: 7181
Reputation: 6982
What I have got from you question that you have some javascript function in your master page, that you want to call from a specific aspx page.
Suppose you have a javascript function hello
in your master page. as :
<script type="text/javascript">
function hello(name) {
alert('hello '+ name);
}
</script>
this you can call in the page load event of any aspx page using Page.RegisterStartupScript
as :
Page.RegisterStartupScript("hi", "<script>hello('Sanjeev')</script>");
So will be able to call master page's javascript function form your aspx page code behind.
Upvotes: 3