为什么页面和控件都设置了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;">
                    &nbsp; 专家组编号:</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">
                    &nbsp; 专家组名称:</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">
                    &nbsp; 专家组类型:</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">
                    &nbsp; 专家组成员:</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>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td colspan="2" style="width: 30%; height: 28px; background-color: #ffffff">
                    &nbsp; 专家组组长:</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>

解决方案 »

  1.   

    <asp:TextBox ID="TextBox1" runat="server" EnableViewState="true"  Width="80.5%"></asp:TextBox>  
    回传后是否重新设置了
      

  2.   

    不知道是不是后台代码有问题啊。楼主把btRelease_Click这个方法贴上来看看
      

  3.   

    首先要肯定是如果是回发的话,
    不管是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中的数据的!!
    最有可能回发后,在什么地方又将它清空了!!
      

  4.   

    明白了,是btRelease_Click里有
    Response.Write("<script language=javascript>alert('创建失败')</script>");
    Response.Write("<script>document.location=document.location;</script>");
    没有这一句的话,字体会变大!!!
    谁能提供类似的弹出提示框的代码吗,谢谢了
      

  5.   

    明白了,是btRelease_Click里有 
    Response.Write(" <script language=javascript>alert('创建失败') </script>"); 
    Response.Write(" <script>document.location=document.location; </script>"); 
    没有这一句的话,字体会变大!!! 
    谁能提供类似的弹出提示框的代码吗,谢谢了
      

  6.   

    Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "document.location=document.location;", true);
      

  7.   

    弹出提示框:
    Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "alert('提示!!')", true);