1、关于updatepanel注册js
最近在项目里需要用到altas,本人也是新手,老用最简单的updatepanel,在注册脚本时也遇到了困难,无法注册。本来是在updatepanel中放了一个gridview,偶想在girdview中一个模板列点击弹出一个窗体,注册window.open()来解决问题。本来不是在updatepanel中,所以用ClientScript.RegisterStartupScript直接注册挺好使。 字串4
在拖入updatepanel后发现无法注册脚本,想想RegisterStartupScript本来是在页面加载时启动js的,在updatepanel中部分刷新,肯定是无法注册的。 字串6
后来发现了ScriptManager.RegisterStartupScript方法,挺好使,呵呵。
ScriptManager.RegisterClientScriptBlock(UpdatePanelName, typeof(UpdatePanel), "标识key", "脚本", true);
下面是一个demo,模板列定义如下:
字串4
字串8
在GridView对应的RowCommand事件中如下操作:
protected void gvClientInfo_RowCommand(object sender, GridViewCommandEventArgs e)
{
//如果是linkButton被点击
if(e.CommandName.Equals("linkbtnCID"))
{
LinkButton lbtn = (LinkButton)e.CommandSource;
GridViewRow dgRow = (GridViewRow)lbtn.Parent.Parent;
string tmpText = lbtn.Text.ToString();
tmpText ="window.open('customerDetailsInfo.aspx?CID=" tmpText "' ,'newwindow','height=550,
width=700, menubar=no ')";
ScriptManager.RegisterStartupScript(this.UpdatePanel2, this.GetType(), "click", tmpText, true);
}
}
2、关于RegisterStartupScript,RegisterClientScriptBlock
RegisterStartupScript 将 js嵌入到页面的底部, 的前面 字串8
RegisterClientScriptBlock 将 js嵌入到页面中开启元素
![我要研发网[www.51dev.com]](/templets/images/toplogo.gif)
