0

我如何创建从内容页面到母版页面加载的 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">
4

1 回答 1

0

回答...

        HtmlGenericControl form = (HtmlGenericControl)

        Page.Master.FindControl("MyBody");

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

母版页

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

在母版页中,通过提供 runat="server" 属性和名称使主体成为控件。

于 2012-08-21T00:19:59.327 回答