how can i create javascript from content page to master page load

393 Views Asked by At

how can i create javascript from content page to master page load

mycontentpage.aspx code behind;

protected void haritasifirla()
        {
            string api = "AIzaSyDZd5O6jx8C4YdrUfMeMywlR5BDCMl4GV0";
            ClientScript.RegisterClientScriptBlock(GetType(), "Script1", "<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=" + api + "' type='text/javascript'></script>");
            StringBuilder sb = new StringBuilder();
            sb.Append("<script type='text/javascript'>");
            sb.Append("function MapLoad() ");
            sb.Append("{");
            sb.Append("if (GBrowserIsCompatible()) ");
            sb.Append("{");

            sb.Append("}");
            sb.Append("}");
            sb.Append("</script>");
            ClientScript.RegisterClientScriptBlock(GetType(), "Script2", sb.ToString());



        }

now

<form id="form1" runat="server">

but i want to

<form id="form1" runat="server" onload="MapLoad">
1

There are 1 best solutions below

0
On

answer...

        HtmlGenericControl form = (HtmlGenericControl)

        Page.Master.FindControl("MyBody");

        form.Attributes.Add("onload", "HaritaYukle()"); 

masterpage

<body runat="server" id="MyBody">

In the master page make the body a control by giving the runat="server" attribute and a name.