ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alert", "alert('更新成功!')", true);
修改后跳到另一個(gè)頁面中去時(shí),可以使用:
ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "click", "location.replace('UserManger.aspx');", true);
如果跳轉(zhuǎn)前還有提示信息的話,則可以使用:
??????? {
??????????? ScriptManager . RegisterStartupScript( this .UpdatePanel1, this .GetType(), " 提示 ", " alert ('" + str_Message + "')", true);
??????? }
<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); ??????????? 關(guān)于updatepanel中注冊執(zhí)行javascript ??? 好些天都在糊里糊涂,最近也比較懶,居然看到了個(gè)留言,永遠(yuǎn)不更新的博客一等獎(jiǎng),相當(dāng)尷尬,哈哈。寫一些最近自己或別人遇到的小問題吧。 ??? 1、關(guān)于updatepanel注冊js ??? 最近在項(xiàng)目里需要用到altas,本人也是新手,老用最簡單的updatepanel,在注冊腳本時(shí)也遇到了困難,無法注冊。本來是在 updatepanel中放了一個(gè)gridview,偶想在girdview中一個(gè)模板列點(diǎn)擊彈出一個(gè)窗體,注冊window.open()來解決問題。本來不是在updatepanel中,所以用ClientScript.RegisterStartupScript直接注冊挺好使。 ??? 在拖入updatepanel后發(fā)現(xiàn)無法注冊腳本,想想RegisterStartupScript本來是在頁面加載時(shí)啟動(dòng)js的,在updatepanel中部分刷新,肯定是無法注冊的。 ??? 后來發(fā)現(xiàn)了ScriptManager.RegisterStartupScript方法,挺好使,呵呵。 ??? ScriptManager.RegisterClientScriptBlock(UpdatePanelName, typeof(UpdatePanel), "標(biāo)識(shí)key", "腳本", true); ??? 下面是一個(gè)demo,模板列定義如下: <asp:TemplateField HeaderText="客戶ID"> ???? <ItemTemplate>??????????? ?????? <asp:LinkButton ID="linkbtnCID" runat="server" Text='<%# Eval("CID") %>' CommandName="linkbtnCID"?? >????????????????????? </asp:LinkButton> ????? </ItemTemplate> </asp:TemplateField> ?? ??? 在GridView對應(yīng)的RowCommand事件中如下操作: protected void gvClientInfo_RowCommand(object sender, GridViewCommandEventArgs e) ??? { ??????? //如果是linkButton被點(diǎn)擊 ??????? 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、關(guān)于RegisterStartupScript,RegisterClientScriptBlock ??????? RegisterStartupScript 將 js嵌入到頁面的底部,</form> 的前面 ??????? RegisterClientScriptBlock 將 js嵌入到頁面中開啟元素 <form> 后面 ??? 3、關(guān)于“該行已經(jīng)屬于另一個(gè)表”錯(cuò)誤 ?????? 這個(gè)問是出現(xiàn)在不同dataTable之間的行復(fù)制出現(xiàn)的問題。 ?????? 看這個(gè)代碼: ?????? DataTable tmpdt = sodo.getDataTable("text", strSql, sp);???????????? dt.Rows.Add(tmpdt.Rows[0]); ??? ???? 這個(gè)明顯的錯(cuò)誤就是tmpdt的行是一個(gè)對象引用,相當(dāng)于一個(gè)指針,錯(cuò)誤是難免的,可有以下解決辦法: DataTable tmpdt = sodo.getDataTable("text", strSql, sp);???????????? 1、 dt.Rows.Add(tmpdt.Rows[0].ItemArray); 2、 dt.ImportRow(tmpdt.Rows[0]); |
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
