如何从内容页面创建javascript到主页面加载

时间:2012-08-21 00:10:31

标签: c# master-pages content-pages

如何从内容页面创建javascript到主页加载

mycontentpage.aspx代码背后;

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());



        }

现在

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

但我想

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

1 个答案:

答案 0 :(得分:0)

...应答

        HtmlGenericControl form = (HtmlGenericControl)

        Page.Master.FindControl("MyBody");

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

母版

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

在母版页中,通过给出runat =“server”属性和名称使主体成为控件。