Is it possible to execute Server side code before executing client side code in ASP.Net
I have a 开发者_如何学JAVALink button in DataGrid
for to edit the grid data, I'm using OnClientClick
event for loading a modal form and also i'm using onSelectedIndexChanged
event function of the GRID for loading editing data to to controls. see the server side code below
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();
}
}
}
see the Client side code for invoking the modal window,
function EditDialog(){
$('#newTeam').dialog("open");
alert(document.Team.txtTeamCode.value);
document.getElementById("cvCode").innerHTML = '';
document.Team.txtTeamCode.focus();
}
The problem is, while poping up the modal form, the fields (team code & team name) are getting blank. Please provide a solution to solve this issue.
You could use an AJAX request to populate the modal pop-up's fields - call an object/service that would return the required data items and then modify the GUI accordingly.
Take a look at JQuery's get() function. For usability it's probably best to do this asynchronously.
Here's a decent tutorial that offers a possible implementation.
HTH
You can make use of httphandlers or as the prev user mentioned make ajax calls. You can also make use of Pagemethods to call the server side code from javascript.
精彩评论