zoukankan      html  css  js  c++  java
  • Unknown error in Atlas UpdatePanel


    在Asp.net 2.0里使用Atlas的UpdatePanel的时候遇到一个问题:在服务器端注册使用JS的脚本会无法使用,一般会提示 "Unknown error"

    经过测试发现可以如此解决.

    1.服务器端注册JS脚本的时候使用 Page.ClientScript.RegisterStartupScript() 或 Page.ClientScript.RegisterClientScriptBlock(),不使用Page.RegisterStartupScript()和Page.RegisterClientScriptBlock()
     前两个方法是Asp.net 2.0里用来代替后面两个在Asp.net1.1里的两个注册脚本的方法的.参考:http://msdn2.microsoft.com/zh-CN/library/z9h4dk8y.aspx

    http://www.microsoft.com/china/msdn/library/webservices/asp.net/JAVAwASP2.mspx?mfr=true
    如下:

    AtlasUpdatePanelTest.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="AtlasUpdatePanelTest.aspx.cs" Inherits="AtlasUpdatePanelTest" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        
    <title>无标题页</title>
    </head>
    <body>
        
    <form id="form1" runat="server">
        
    <atlas:ScriptManager ID="ScriptManager" runat="server" EnablePartialRendering="true" />
            
    <h4>
                With an UpdatePanel
    </h4>
            
    <!-- This section of the page is wrapped by an UpdatePanel. -->
            
    <atlas:UpdatePanel ID="up" runat="server" Mode="Conditional" RenderMode="Inline">
                
    <ContentTemplate>
                    
    &nbsp;<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" OnTextChanged="TextBox1_TextChanged"></asp:TextBox><br />
                    
    &nbsp;<asp:Label ID="Label1" runat="server"></asp:Label><br />
                    
    <asp:Button ID="BtnTest" runat="server" OnClick="BtnTest_Click" Text="TestJavaScript" />
                
    </ContentTemplate>
            
    </atlas:UpdatePanel>
            
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="OutUpdatePanel" />
        
    </form>
    </body>
    </html>

    AtlasUpdatePanelTest.aspx.cs

    public partial class AtlasUpdatePanelTest : System.Web.UI.Page
    {
        
    protected void Page_Load(object sender, EventArgs e)
        
    {

        }

        
    protected void TextBox1_TextChanged(object sender, EventArgs e)
        
    {
            Label1.Text 
    = TextBox1.Text;
        }

        
    protected void BtnTest_Click(object sender, EventArgs e)
        
    {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), 
    "TestJS"@"alert(""Page.ClientScript.RegisterStartupScript"")"true);
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), 
    "TestJS"@"alert(""Page.ClientScript.RegisterClientScriptBlock"")"true);
           
    // Response.Write("<script>alert('a')</script>");  //无法在Atlas UpdatePanel里使用
           
    //Page.RegisterStartupScript("Test", "<script>alert('Page.RegisterStartupScript')</script>"); ////无法在Atlas UpdatePanel里使用
        }

        
    protected void Button1_Click(object sender, EventArgs e)
        
    {
           
    //不在Atlas UpdatePanel 里可以使用
            Response.Write("<script>alert('a')</script>");
            Page.RegisterStartupScript(
    "Test""<script>alert('Page.RegisterStartupScript')</script>");
        }

    }

  • 相关阅读:
    python paramiko模块学习分享
    中国大数据市场规模分析及预测
    中国大数据市场规模分析及预测
    显著性水平 置信度 置信区间 实例讲解
    显著性水平 置信度 置信区间 实例讲解
    加密算法
    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'qingmu' for key 'PRIMARY'
    spring Security的自定义用户认证
    spring的面试题
    solr和ElasticSearch(ES)的区别?
  • 原文地址:https://www.cnblogs.com/adandelion/p/513504.html
Copyright © 2011-2022 走看看