C# WebForms在post上不断显示事件验证错误

C# WebForms在post上不断显示事件验证错误,c#,post,webforms,eventvalidation,C#,Post,Webforms,Eventvalidation,当我尝试将信息从客户端提交到服务器时,收到无效的回发或回调参数。使用启用事件验证。我尝试了答案中的大部分建议,但似乎没有帮助 在相关的.aspx页面顶部,添加EnableEventValidation=“false”可以解决问题。然而,我希望这一点保持不变 我还在代码隐藏中添加了(!Page.IsPostBack),这仍然会导致问题 是否是jQuery timpicker根据用户选择的输入值导致了问题 代码隐藏.cs public partial class _Default : Page

当我尝试将信息从客户端提交到服务器时,收到无效的回发或回调参数。使用
启用事件验证。我尝试了答案中的大部分建议,但似乎没有帮助

在相关的.aspx页面顶部,添加EnableEventValidation=“false”可以解决问题。然而,我希望这一点保持不变

我还在代码隐藏中添加了(!Page.IsPostBack),这仍然会导致问题

是否是jQuery timpicker根据用户选择的输入值导致了问题

代码隐藏.cs

public partial class _Default : Page
    {


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var DbHelper = new DbHelper();

                listOfUsers.DataSource = DbHelper.UserList();
                listOfUsers.DataBind();

            }
            else 
            {
                string test = listOfUsers.SelectedValue;
                string time = timePicker.Text;
                string reason = ReasonForRemoval.Text;

            }
        }
    }
.aspx文件

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="xxxMyProjectNamexxx" EnableEventValidation="true"%>

<%--<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>--%>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">


<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js' type='text/javascript'></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>


<script type="text/javascript" src="/Scripts/jquery-ui-timepicker-addon.js"></script>
<link rel="stylesheet" href="/Styles/jquery-ui-timepicker-addon.css">

  <script type="text/javascript">
      jQuery(document).ready(function ($) {
          $('[id*=timePicker]').timepicker({
              timeFormat: "hh:mm:ss"
          });
      });
  </script>

    <head>
        <h2>
            My App
        </h2>
        <p>
    Enter relevant info
        </p>
    </head>
    <body>
        <form method="post">
            <div>
            <label for="UserName">User Name:</label>
            <asp:DropDownList ID="listOfUsers" runat="server"></asp:DropDownList>
            </div>
            <br/><br/>
            <table>
            <tr>
            <th>
            <div>
            <label for="Time">Time:</label>
            <asp:TextBox ID="timePicker" runat="server"></asp:TextBox>
            </div>
            </th>
            </tr>
            </table>
            <br/><br/>
            <div>
            <label for="Reason">Reaso:</label>
            <br/>
            <asp:TextBox ID="ReasonForRemoval" runat="server" TextMode="MultiLine" Rows="5" Width="400px" style="resize:none"></asp:TextBox>
          </div>
          <br/><br/>
            <div>
            <label>&nbsp;</label>
            <input type="submit" value="Submit" class="submit" />
          </div>
        </form>
    </body>
</asp:Content>

jQuery(文档).ready(函数($){
$('[id*=timePicker]')。timePicker({
时间格式:“hh:mm:ss”
});
});
我的应用程序

输入相关信息

用户名:

时间:

原因:


用于生成列表的DbHelper.cs

    public class DbHelper
    {
        private EntityConnection entCon;

        public DbHelper() 
        {
            entCon = new EntityConnection(ConfigurationManager.ConnectionStrings["myConnString"].ConnectionString);

        }

        public List<string> UserList() 
        {
            List<string> userList = new List<string>();

            using(SqlConnection conn = (SqlConnection)entCon.StoreConnection)
            using (SqlCommand cmd = new SqlCommand()) 
            {
                conn.Open();
                cmd.Connection = conn;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "SELECT * FROM [MyDatabase].[dbo].[users]";

                using (SqlDataReader objReader = cmd.ExecuteReader()) 
                {
                    if (objReader.HasRows) 
                    {
                        while (objReader.Read()) 
                        {
                            userList.Add(Convert.ToString(objReader[0]));
                        }
                    }
                }
            }
            return userList;
        }
    }
}
公共类DbHelper
{
私有实体连接entCon;
公共DbHelper()
{
entCon=新的EntityConnection(ConfigurationManager.ConnectionString[“myConnString”].ConnectionString);
}
公共列表用户列表()
{
List userList=新列表();
使用(SqlConnection conn=(SqlConnection)entCon.StoreConnection)
使用(SqlCommand cmd=new SqlCommand())
{
conn.Open();
cmd.Connection=conn;
cmd.CommandType=CommandType.Text;
cmd.CommandText=“从[MyDatabase].[dbo].[users]中选择*”;
使用(SqlDataReader objReader=cmd.ExecuteReader())
{
if(objReader.HasRows)
{
while(objReader.Read())
{
userList.Add(Convert.ToString(objReader[0]);
}
}
}
}
返回用户列表;
}
}
}