textbox的值不能保存

messi2255 2009-12-06 11:30:07
为什么页面和控件都设置了EnableViewState后点击创建后textbox1的内容还是会被刷掉???
配置文件里没有配置这一项
<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="true" CodeFile="AddExpertGroup.aspx.cs" Inherits="SchoolAdmin_AddExpertGroup" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

</head>
<body style="background:#C4D8ED;">
<form id="form1" runat="server">
<table border="0" cellspacing="1" cellpadding="3" align="center" width="100%" style="margin-left:0px; margin-top:0px;border-collapse: collapse;color:#135294;font-size:13px;">
<tr>
<td colspan="3" style="background:#FFFFFF; color:#135294; padding:2px; height: 27px;font-size:13px; font-weight: bold;" align="left">
创建专家组</td>
</tr>
<tr>
<td colspan="2" style="width: 30%; background-color: #eef7fd; height: 28px;">
  专家组编号:</td>
<td style="width: 79%; background-color: #eef7fd; height: 28px;">
<asp:TextBox ID="TextBox1" runat="server" EnableViewState="true" Width="80.5%" AutoPostBack="True"></asp:TextBox> </tr>
<tr>
<td colspan="2" style="width: 30%; height: 28px; background-color: #ffffff">
  专家组名称:</td>
<td style="width: 79%; height: 28px; background-color: #ffffff">
<asp:TextBox ID="TextBox2" runat="server" Style="width: 80.5%" AutoPostBack="True"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2" style="width: 30%; height: 28px; background-color: #eef7fd">
  专家组类型:</td>
<td style="width: 79%; height: 28px; background-color: #eef7fd">
<asp:DropDownList ID="DropDownList3" runat="server" Width="81.5%" AutoPostBack="True">
<asp:ListItem>评审</asp:ListItem>
<asp:ListItem>评分</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td colspan="2" style="width: 30%; height: 28px; background-color: #ffffff">
  专家组成员:</td>
<td style="width: 79%; height: 28px; background-color: #ffffff">
<asp:DropDownList ID="DropDownList1" runat="server" Style="width: 71%" AutoPostBack="True">
</asp:DropDownList>
<input id="Button1" type="button" value="配置成员" style="width:10%; font-size:12px;" language="javascript" onclick="return Button1_onclick()" /></td>
</tr>
<tr>
<td colspan="2" style="width: 30%; height: 28px; background-color: #eef7fd">
</td>
<td style="width: 79%; height: 28px; background-color: #eef7fd">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
BackColor="Black" BorderColor="White" BorderWidth="1px" CellPadding="3" DataKeyNames="UserID"
OnPreRender="GridView1_PreRender" Width="80%" PageSize="5">
<PagerSettings Position="Top" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="选择">
<HeaderTemplate>
<input type="checkbox" id="AllSelectCheckBox" onclick="selectAll(this)" />全选
</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<asp:CheckBox ID="OneSelectCheckBox" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="姓名" SortExpression="Name">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="studyto" HeaderText="研究方向" SortExpression="Tel">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
</Columns>
<PagerTemplate>
<table style="width: 100%;">
<tr>
<td align="left">
<asp:Button ID="btNewCreat" OnClick="btNewCreat_Click" runat="server" Font-Size="12px" Height="20px" Text="添加到专家组"
Width="80px" />
</td>
<td align="right">
<asp:LinkButton ID="cmdFirstPage" runat="server" CommandArgument="First" CommandName="Page"
Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>">首页</asp:LinkButton>
<asp:LinkButton ID="cmdPreview" runat="server" CommandArgument="Prev" CommandName="Page"
Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>">前一页</asp:LinkButton>
第<asp:Label ID="lblcurPage" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex+1 %>'></asp:Label>页/共<asp:Label
ID="lblPageCount" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageCount %>'></asp:Label>页
<asp:LinkButton ID="cmdNext" runat="server" CommandArgument="Next" CommandName="Page"
Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">后一页</asp:LinkButton>
<asp:LinkButton ID="cmdLastPage" runat="server" CommandArgument="Last" CommandName="Page"
Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">尾页</asp:LinkButton>
转<asp:TextBox ID="txtGoPage" runat="server" CssClass="inputmini" Height="12px" OnTextChanged="txtGoPage_TextChanged"
Text='<%# ((GridView)Container.Parent.Parent).PageIndex+1 %>' Width="32px"></asp:TextBox>页
</td>
</tr>
</table>
</PagerTemplate>
<RowStyle BackColor="#EEF7FD" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#E4EDF9" ForeColor="#4A3C8C" HorizontalAlign="Center" />
<HeaderStyle BackColor="#E4EDF9" Font-Bold="True" ForeColor="#135294" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
 
</td>
</tr>
<tr>
<td colspan="2" style="width: 30%; height: 28px; background-color: #ffffff">
  专家组组长:</td>
<td style="width: 79%; height: 28px; background-color: #ffffff">
<asp:TextBox ID="TextBox3" runat="server" Style="width: 70%" AutoPostBack="True"></asp:TextBox>
<asp:DropDownList ID="DropDownList2" runat="server" Style="width: 10%" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" AutoPostBack="True">

</asp:DropDownList></td>
</tr>
<tr>
<td colspan="3" style="height: 25px; background-color: #e4edf9">
<asp:Button ID="btRelease" runat="server" Text="创建" style=" margin-left: 40%; width:62px; height:22px;" OnClick="btRelease_Click"/>
<input id="btBack" type="button" value="返回" onclick="link1()" style=" margin-left: 10%; width:62px; height:22px;" /></td>
</tr>
</table>
</form>
</body>
</html>
...全文
102 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
happy664618843 2009-12-06
  • 打赏
  • 举报
回复
服务器回发将视图状态重置了
koukoujiayi 2009-12-06
  • 打赏
  • 举报
回复
弹出提示框:
Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "alert('提示!!')", true);
koukoujiayi 2009-12-06
  • 打赏
  • 举报
回复
Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "document.location=document.location;", true);
红街咖啡 2009-12-06
  • 打赏
  • 举报
回复
哦。这样子
messi2255 2009-12-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jxyxhz 的回复:]
不知道是不是后台代码有问题啊。

楼主把btRelease_Click这个方法贴上来看看
[/Quote]
明白了,是btRelease_Click里有
Response.Write(" <script language=javascript>alert('创建失败') </script>");
Response.Write(" <script>document.location=document.location; </script>");
没有这一句的话,字体会变大!!!
谁能提供类似的弹出提示框的代码吗,谢谢了。。。
messi2255 2009-12-06
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 koukoujiayi 的回复:]
首先要肯定是如果是回发的话,
不管是EnableViewState="true"或者为false都能保持TextBox中的数据不变,
这是回发机制所决定的
根据你的代码,你可以在新的页面仅试这两句:
    <asp:TextBox ID="TextBox1" runat="server"  Width="80.5%" AutoPostBack="True"> </asp:TextBox>
    <asp:Button ID="btRelease" runat="server" Text="创建" style=" margin-left: 40%; width:62px; height:22px;" OnClick="btRelease_Click"/>
那一定是保留特TextBox中的数据的!!
最有可能回发后,在什么地方又将它清空了!!
[/Quote]
明白了,是btRelease_Click里有
Response.Write("<script language=javascript>alert('创建失败')</script>");
Response.Write("<script>document.location=document.location;</script>");
没有这一句的话,字体会变大!!!
谁能提供类似的弹出提示框的代码吗,谢谢了。。。
koukoujiayi 2009-12-06
  • 打赏
  • 举报
回复
首先要肯定是如果是回发的话,
不管是EnableViewState="true"或者为false都能保持TextBox中的数据不变,
这是回发机制所决定的
根据你的代码,你可以在新的页面仅试这两句:
<asp:TextBox ID="TextBox1" runat="server" Width="80.5%" AutoPostBack="True"></asp:TextBox>
<asp:Button ID="btRelease" runat="server" Text="创建" style=" margin-left: 40%; width:62px; height:22px;" OnClick="btRelease_Click"/>
那一定是保留特TextBox中的数据的!!
最有可能回发后,在什么地方又将它清空了!!
lovexilove 2009-12-06
  • 打赏
  • 举报
回复
帖了一堆代码 实际上没几行有用
小_虎 2009-12-06
  • 打赏
  • 举报
回复
不知道是不是后台代码有问题啊。

楼主把btRelease_Click这个方法贴上来看看
wuyq11 2009-12-06
  • 打赏
  • 举报
回复
<asp:TextBox ID="TextBox1" runat="server" EnableViewState="true" Width="80.5%"></asp:TextBox>
回传后是否重新设置了

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧