Javascript 正在尝试更新div InnerHtml,但什么都没有发生
我的网页上有一个html表,它显示了我从MySql数据库中提取的数据。当用户单击其中一个表行时,根据该行中的数据,页面上的另一个div应该会更新并显示其他信息。问题是,当我试图从我的c#代码隐藏页面更新div的内部html时,什么都没有发生。开发人员控制台中没有错误,没有抛出异常,什么都没有。为什么会发生这种情况?我如何修复它?我做错了什么 通过c代码生成的HTML表格数据: 应该更新div内部html的方法:Javascript 正在尝试更新div InnerHtml,但什么都没有发生,javascript,c#,jquery,asp.net,Javascript,C#,Jquery,Asp.net,我的网页上有一个html表,它显示了我从MySql数据库中提取的数据。当用户单击其中一个表行时,根据该行中的数据,页面上的另一个div应该会更新并显示其他信息。问题是,当我试图从我的c#代码隐藏页面更新div的内部html时,什么都没有发生。开发人员控制台中没有错误,没有抛出异常,什么都没有。为什么会发生这种情况?我如何修复它?我做错了什么 通过c代码生成的HTML表格数据: 应该更新div内部html的方法: protected void SpecificUser(string id)
protected void SpecificUser(string id)
{
System.Windows.Forms.MessageBox.Show(id);
Query query = new Query();
User specificUser = new User();
specificUser = query.GetUserSpecifics(Convert.ToInt32(id));
string newFormRow = "<div runat=\"server\" class=\"form-row\">";
string newFormGroup = "<div runat=\"server\" class=\"form-group\">";
string newFormGroupCol = "<div runat=\"server\" class=\"form-group col-md-6\">";
string closeDiv = "</div>";
string UserDataHTML1 = string.Format("" +
newFormRow +
"<label id=\"userIDLabel1\">User ID:</label>" +
"<label id=\"userIDLabel2\">{0}</label>" +
closeDiv +
newFormRow +
newFormGroupCol +
"<label id=\"lblFName\" for=\"txtFName\">First Name: </label>" +
"<input id=\"txtFName\" class=\"form-control\" runat=\"server\" type=\"text\" value={1} />" +
closeDiv +
newFormGroupCol +
"<label id=\"lblLName\" for=\"txtLName\">Last Name: </label>" +
"<input id=\"txtFName\" class=\"form-control\" runat=\"server\" type=\"text\" value={2} />" +
closeDiv +
closeDiv, id, specificUser.fName, specificUser.lName);
userDataDiv.InnerHtml = UserDataHTML1;
}
受保护的用户(字符串id)
{
System.Windows.Forms.MessageBox.Show(id);
查询=新查询();
用户特定用户=新用户();
specificUser=query.GetUserSpecifics(Convert.ToInt32(id));
字符串newFormRow=“”;
字符串newFormGroup=“”;
字符串newFormGroupCol=“”;
字符串closeDiv=“”;
string UserDataHTML1=string.Format(“”)+
纽福罗+
“用户ID:”+
"{0}" +
密室+
纽福罗+
新表单组+
“名字:”+
"" +
密室+
新表单组+
“姓氏:”+
"" +
密室+
closeDiv,id,specifiuser.fName,specifiuser.lName);
userDataDiv.InnerHtml=UserDataHTML1;
}
任何帮助都将不胜感激!谢谢 要更新html内容,您应该将C#route的响应发送回客户端,并使用jQuery对接收到的数据更新html部分您不能将
runat=server
添加到字符串中,并期望它的行为类似于服务器控件,这样做是行不通的。将所有内容创建为字符串时所做的操作都很混乱,并且会导致错误。使用“真实”控件,如GridView、Repeater、Panel等,不要在Web应用程序中使用System.Windows.Forms
。
function viewUserSpecifics(id) {
var data = id;
var xmlHttpRequest;
xmlHttpRequest = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("testing.XMLHTTP");
if (xmlHttpRequest == null) {
alert("ajax not supported");
return null;
}
xmlHttpRequest.open("GET", "ManagerPopup.aspx?ID=" + data, true);
xmlHttpRequest.send(null);
//document.getElementById('userDataDiv').innerHTML.
}
$(document).ready(function () {
$('#userListTable tbody').on('click', 'tr', function () {
var tableData = $(this).children("td").map(function () {
return $(this).text();
}).get();
//$("#< %= userIDHidden.ClientID %>").val($.trim(tableData[0]));
//alert($.trim(tableData[0]));
viewUserSpecifics($.trim(tableData[0]));
return false;
});
});
protected void Page_Load(object sender, EventArgs e)
{
PopulateUsers(true);
if (Request.QueryString["ID"] != null)
{
string ID = Request.QueryString["ID"];
SpecificUser(ID);
}
}
protected void SpecificUser(string id)
{
System.Windows.Forms.MessageBox.Show(id);
Query query = new Query();
User specificUser = new User();
specificUser = query.GetUserSpecifics(Convert.ToInt32(id));
string newFormRow = "<div runat=\"server\" class=\"form-row\">";
string newFormGroup = "<div runat=\"server\" class=\"form-group\">";
string newFormGroupCol = "<div runat=\"server\" class=\"form-group col-md-6\">";
string closeDiv = "</div>";
string UserDataHTML1 = string.Format("" +
newFormRow +
"<label id=\"userIDLabel1\">User ID:</label>" +
"<label id=\"userIDLabel2\">{0}</label>" +
closeDiv +
newFormRow +
newFormGroupCol +
"<label id=\"lblFName\" for=\"txtFName\">First Name: </label>" +
"<input id=\"txtFName\" class=\"form-control\" runat=\"server\" type=\"text\" value={1} />" +
closeDiv +
newFormGroupCol +
"<label id=\"lblLName\" for=\"txtLName\">Last Name: </label>" +
"<input id=\"txtFName\" class=\"form-control\" runat=\"server\" type=\"text\" value={2} />" +
closeDiv +
closeDiv, id, specificUser.fName, specificUser.lName);
userDataDiv.InnerHtml = UserDataHTML1;
}