码迷,mamicode.com
首页 > Web开发 > 详细

NET使用了UpdatePanel后如何弹出对话框!

时间:2017-08-31 12:51:55      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:简单   add   comm   oca   oid   购物   无法   datatable   array   

在ajax中的UpdatePanel弹出对话窗,可以使用:

ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alert", "alert(‘更新成功!‘)", true);

修改后跳到另一个页面中去时,可以使用:
ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "click", "location.replace(‘UserManger.aspx‘);", true);

如果跳转前还有提示信息的话,则可以使用:

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "click", "alert(‘更新成功!‘);location.replace(‘UserManger.aspx‘);", true);
 
例如:ScriptManager.RegisterStartupScript(this.UpdatePanel1,this.GetType(), "提示", "alert(‘购物车为空,请先购物!‘)", true);  
 
 protected void UpdatePanelAlert(string str_Message)
        {
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "提示", "alert(‘" + str_Message + "‘)", true);
        }
 UpdatePanelAlert("无此代码");
/////////////////////////////////////////////////////////////////////////////////////////////
asp.net ajax框架UpdatePanel弹出提示的几种方法
2009-06-09 14:15
<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中注册执行javascript

    好些天都在糊里糊涂,最近也比较懒,居然看到了个留言,永远不更新的博客一等奖,相当尴尬,哈哈。写一些最近自己或别人遇到的小问题吧。
    1、关于updatepanel注册js
    最近在项目里需要用到altas,本人也是新手,老用最简单的updatepanel,在注册脚本时也遇到了困难,无法注册。本来是在 updatepanel中放了一个gridview,偶想在girdview中一个模板列点击弹出一个窗体,注册window.open()来解决问题。本来不是在updatepanel中,所以用ClientScript.RegisterStartupScript直接注册挺好使。
    在拖入updatepanel后发现无法注册脚本,想想RegisterStartupScript本来是在页面加载时启动js的,在updatepanel中部分刷新,肯定是无法注册的。
    后来发现了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、关于“该行已经属于另一个表”错误
       这个问是出现在不同dataTable之间的行复制出现的问题。
       看这个代码:
       
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]);

NET使用了UpdatePanel后如何弹出对话框!

标签:简单   add   comm   oca   oid   购物   无法   datatable   array   

原文地址:http://www.cnblogs.com/skyboy110/p/7457365.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!