c# 通过ICallbackEventHandler 实现页面“无刷新”

C#   前台代码

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/jscript">
function getvalue()
{
    var value1 =document.getElementById("Text1").value;
    var aa ="";
    <%=gg() %>  
}
function setvalue(result)
{
document.getElementById("Text2").value=result;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="Text1" type="text" />
        <input id="Button1" type="button" value="button" onclick="getvalue();"/>
        <input id="Text2" type="text" />
    </div>
    </form>
</body>
</html>

 

c#后台代码

 

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 Default25 : System.Web.UI.Page,ICallbackEventHandler
{
    string testvalue = "";
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public string gg()
    {
        return ClientScript.GetCallbackEventReference(this, "value1", "setvalue", "aa");
    }

    #region ICallbackEventHandler 成员

    public string GetCallbackResult()
    {
        return testvalue;
    }

    public void RaiseCallbackEvent(string eventArgument)
    {
        testvalue = eventArgument + "1";
    }

    #endregion

posted on 2008-11-04 08:55  AlexGeng  阅读(769)  评论(0编辑  收藏  举报

导航