zoukankan      html  css  js  c++  java
  • change page at client

    this airticle content two methods about update page synchronousy ajax and asp.net.

    first method is the original,second is contented by asp.net2.0

    compare them and use them. Good Luck!

    1.Transparent server request

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

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">

         <title>Test</title>

         <script type="text/javascript">

         function DoCalc(val)

         {

          var url="multiply.aspx?val="+val;

          var request=null;

          if(window.XMLHttpRequest)

           {

           request=new XMLHttpRequest();

           request.open("GET",url,false);

           request.send();

          }

          else if(window.ActiveObject)

                {

                 request=new ActiveXObject("Microsoft.XMLHttp");

                 request.open("GET",url,false);

                 request.send();

                }

           if(request)

           {

           var result=request.responseText;

           alert(result);

           }

        }

        </script>

    </head>

    <body>

          <form id="form1" runat="server">

               <asp:TextBox ID="txtvalue" runat="server" />

               <input id="btnSubmit" runat="server" type="button" value="Calc"

                 onclick="javascript:DoCalc(document.getElementById('txtvalue').value");"/>

          </form>

    </body>

    </html>

    multiply.aspx

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Data" %>
    <%@ import Namespace="System.IO" %>

    <script type="text/C#" language ="C#" runat ="server">

    protected void Page_Load()

    {

    int val=int.Parse(this.Request.QueryingString["val"]);

    Response.Write((var*2).ToString());

    Response.Flush();

    Response.End();

    }

    </script>

    2.ASP.NET script_callback

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

    <!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>Test</title>
        <script type="text/javascript">
        function showresult(result,context)
        {
        alert(result);
        }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <div id="div0" style="position: static; background-color: blue; 728px; height: 376px;">
        <asp:TextBox ID="txtvalue" runat="server" Style="z-index: 100; left: 240px; position: absolute;
                top: 192px"></asp:TextBox>
            <input id="btnsubmit" style="z-index: 101; left: 256px; position: absolute; top: 256px;

              120px; height: 32px;"
                type="button" value="Calc" runat="server"/>
        </div>
        </div>
        </form>
    </body>
    </html>

    Default2.aspx.cs

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class Default2 : Huima.UI.BasePage, ICallbackEventHandler
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string callbackref = this.ClientScript.GetCallbackEventReference(

            this, "window.document.getElementById('txtvalue').value", "showresult", null);
            btnsubmit.Attributes.Add("onclick", callbackref);
        }
        string callbackresult = "";
        public string GetCallbackResult()
        {
            return callbackresult;
        }
        public void RaiseCallbackEvent(string eventArgument)
        {
            callbackresult = (int.Parse(eventArgument) * 2).ToString();
        }
    }

  • 相关阅读:
    从SVN下检出项目内容【步骤】
    添加购物车,或者存入缓冲中
    接触的电商项目中使用框架编写代码的常用点
    sql语句中【模糊查询like的使用】
    总结:String类型与Int类型的转换【实现插入操作主键自增】
    自定义TextView跑马灯效果
    Re-installation failed due to different application signatures解决方案
    使用Afinal提交的数据到服务器时,数据中带空格或是有换行操作时报错【处理方案】
    解决ScrollView嵌套ListView冲突问题,并且添加阻尼效果
    使用eclipse截取客户端当前页图片
  • 原文地址:https://www.cnblogs.com/xiaojun/p/1652729.html
Copyright © 2011-2022 走看看