簡體   English   中英

是否可以在ASP.Net中執行客戶端代碼之前執行服務器端代碼

[英]Is it possible to execute Server side code before executing client side code in ASP.Net

我在DataGrid有一個“鏈接”按鈕,用於編輯網格數據,我正在使用OnClientClick事件加載模式窗體,並且我正在使用GRID的onSelectedIndexChanged事件函數將編輯數據加載到控件中。 請參閱下面的服務器端代碼

    protected void GetSelectedData(Object src, EventArgs e)
{
    String Team_Id = GridView1.DataKeys[GridView1.SelectedIndex].ToString();
    using (MySqlConnection DbConnection = new MySqlConnection(ConfigurationManager.AppSettings["ConnectionStr"]))
    {
        DbConnection.Close();
        string cmdText = "SELECT Team_Id,Team_code,Team_Name FROM Team_Details WHERE Team_Id=?Id";
        MySqlCommand cmd = new MySqlCommand(cmdText, DbConnection);
        cmd.Parameters.Add("?Id", MySqlDbType.Int32).Value = Convert.ToInt32(Team_Id);
        DbConnection.Open();
        MySqlDataReader DR = cmd.ExecuteReader();
        while (DR.Read())
        {
            this.txtTeamCode.Text = DR.GetValue(1).ToString();
            this.txtTeamName.Text = DR.GetValue(2).ToString();

        }
    }
}

請參閱用於調用模式窗口的客戶端代碼,

        function EditDialog(){ 
        $('#newTeam').dialog("open");   
        alert(document.Team.txtTeamCode.value);          
        document.getElementById("cvCode").innerHTML = '';
        document.Team.txtTeamCode.focus();                   
    }        

問題是,當彈出模式表單時,字段(團隊代碼和團隊名稱)變得空白。 請提供解決此問題的解決方案。

您可以使用AJAX請求填充模式彈出窗口的字段-調用將返回所需數據項的對象/服務,然后相應地修改GUI。

看一下JQuery的get()函數。 為了提高可用性,最好是異步執行此操作。

這是一個不錯的教程 ,提供了可能的實現。

HTH

您可以使用httphandlers或作為提到的prev用戶進行ajax調用。 您還可以使用Pagemethods從javascript調用服務器端代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM