小菜鸟求助。我想实现点击PostBack按钮,更新Textbox1的值,但是页面其他部分不刷新。测试时,我先点击SetColor按钮设置表格第6行字体为红色,并在Textbox2中输入任意测试值,在点击PostBack按钮后,Textbox1值被更新,Textbox2中测试值也没变,但是页面有明显的闪屏,同时表格第6行设置的字体颜色也被刷掉了,是什么原因呢?请大神们帮帮忙,跪谢了~!
前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="tt.aspx.cs" Inherits="ASPX_NewKjbb_tt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language="javascript">
function t1() {
tr5.style.color = "red";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="PostBack" runat="server" onclick="Button1_Click" Text="PostBack" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<input ID="BT_SetColor" type="button" value="SetColor" onclick="t1();" />
<div id="Tdiv" runat="server">
</div>
</form>
</body>
</html>
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ASPX_NewKjbb_tt : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
tt();
}
private void tt()
{
Tdiv.InnerHtml = "<table id='tb01' border='1'>";
for (int i = 0; i < 10; i++)
{
Tdiv.InnerHtml = Tdiv.InnerHtml + "<tr id='tr"+i+"'><td>NO:" + i + "</td><td>Test Table Row"+i+"</td>";
}
Tdiv.InnerHtml = Tdiv.InnerHtml + "</table>";
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "PostBack String......";
}
}