文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>asp.net中使用callback

asp.net中使用callback

时间:2011-03-11  来源:象牛

①由用户触发

  1. 在button的 onclick 中写入:
    onclick="<%= ClientScript.GetCallbackEventReference(this,"document.getElementById('txtUserName').value","onCallBack",null) %>" 
  2. 在 xxx.aspx.cs 中继承 ICallbackEventHandler  并实现其方法。
    public partial class webPage_callBackBtn : System.Web.UI.Page, ICallbackEventHandler
    {
    protected string strUserInfo;
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    #region ICallbackEventHandler 成员

    public string GetCallbackResult()
    {
    return strUserInfo;
    }

    public void RaiseCallbackEvent(string eventArgument)
    {
    if (eventArgument == "") return;
    System.Data.SqlClient.SqlConnection conn
    = new System.Data.SqlClient.SqlConnection();
    conn.ConnectionString
    = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["nowthWindConnectionString"].ConnectionString;

    SqlCommand cmd
    = new SqlCommand();
    cmd.CommandType
    = CommandType.Text;
    cmd.Parameters.Add(
    "@FirstName", SqlDbType.NVarChar, 10)
    .Value
    = eventArgument;
    cmd.CommandText
    = "SELECT EmployeeID, LastName FROM Employees WHERE FirstName=@FirstName";
    cmd.Connection
    = conn;

    SqlDataReader reader;
    ConnectionState previousConnectionState
    = conn.State;

    try
    {
    if (conn.State == ConnectionState.Closed)
    {
    conn.Open();
    }

    reader
    = cmd.ExecuteReader();

    using (reader)
    {
    while (reader.Read())
    {
    // Process SprocResults datareader here.
    strUserInfo += reader[0];
    }
    }
    strUserInfo
    += "###";
    }
    finally
    {
    if (previousConnectionState == ConnectionState.Closed)
    {
    conn.Close();
    }
    }
    }

    #endregion
    }
相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载