ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alert", "alert('更新成功!')", true);
修改后跳到另一個頁面中去時,可以使用:
ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "click", "location.replace('UserManger.aspx');", true);
如果跳轉(zhuǎn)前還有提示信息的話,則可以使用:
<asp:UpdatePanel runat="server" ID="p1"> *.cs: Microsoft.Web.UI.ScriptManager.RegisterStartupScript(p1, this.GetType(), "click", "alert('ok')", true); 在ASP.NET的UpdatePanel中不能使用Response.write("")了,感覺不是很方便。 那就用UpdatePanel支持的方法吧! this.ClientScript.RegisterClientScriptBlock(this.GetType(),"a","alert('ok!');",true); for 1.0 ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "click", "alert('ok')", true); System.Web.UI.ScriptManager.RegisterStartupScript(Button1, this.GetType(), "click", "alert('ok')", true); 關于updatepanel中注冊執(zhí)行javascript 好些天都在糊里糊涂,最近也比較懶,居然看到了個留言,永遠不更新的博客一等獎,相當尷尬,哈哈。寫一些最近自己或別人遇到的小問題吧。 1、關于updatepanel注冊js 最近在項目里需要用到altas,本人也是新手,老用最簡單的updatepanel,在注冊腳本時也遇到了困難,無法注冊。本來是在 updatepanel中放了一個gridview,偶想在girdview中一個模板列點擊彈出一個窗體,注冊window.open()來解決問題。本來不是在updatepanel中,所以用ClientScript.RegisterStartupScript直接注冊挺好使。 在拖入updatepanel后發(fā)現(xiàn)無法注冊腳本,想想RegisterStartupScript本來是在頁面加載時啟動js的,在updatepanel中部分刷新,肯定是無法注冊的。 后來發(fā)現(xiàn)了ScriptManager.RegisterStartupScript方法,挺好使,呵呵。 ScriptManager.RegisterClientScriptBlock(UpdatePanelName, typeof(UpdatePanel), "標識key", "腳本", true); 下面是一個demo,模板列定義如下: <asp:TemplateField HeaderText="客戶ID"> <ItemTemplate> <asp:LinkButton ID="linkbtnCID" runat="server" Text='<%# Eval("CID") %>' CommandName="linkbtnCID" > </asp:LinkButton> </ItemTemplate> </asp:TemplateField> 在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嵌入到頁面的底部,</form> 的前面 RegisterClientScriptBlock 將 js嵌入到頁面中開啟元素 <form> 后面 3、關于“該行已經(jīng)屬于另一個表”錯誤 這個問是出現(xiàn)在不同dataTable之間的行復制出現(xiàn)的問題。 看這個代碼: DataTable tmpdt = sodo.getDataTable("text", strSql, sp); dt.Rows.Add(tmpdt.Rows[0]); 這個明顯的錯誤就是tmpdt的行是一個對象引用,相當于一個指針,錯誤是難免的,可有以下解決辦法: DataTable tmpdt = sodo.getDataTable("text", strSql, sp); 1、 dt.Rows.Add(tmpdt.Rows[0].ItemArray); 2、 dt.ImportRow(tmpdt.Rows[0]); |