如何从内容页面创建javascript到主页加载
mycontentpage.aspx代码背后;
protected void haritasifirla()
{
string api = "AIzaSyDZd5O6jx8C4YdrUfMeMywlR5BDCMl4GV0";
ClientScript.RegisterClientScriptBlock(GetType(), "Script1", "<script src='http://maps.google.com/maps?file=api&v=2&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">
答案 0 :(得分:0)
...应答
HtmlGenericControl form = (HtmlGenericControl)
Page.Master.FindControl("MyBody");
form.Attributes.Add("onload", "HaritaYukle()");
母版
<body runat="server" id="MyBody">
在母版页中,通过给出runat =“server”属性和名称使主体成为控件。