1

When I try to submit information from client to server, I receive Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/>. I've tried most of the suggestions in the answers and they don't seem to be helping.

At the top of the .aspx page in question, adding EnableEventValidation="false" does solve the issue. However, I would like to this to remain as set to true.

I've also added (!Page.IsPostBack) in the code behind and this is still causing issues.

Could it be the jQuery timpicker that's causing the issue by inputting values based on what the user selects?

Code behind .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 file

<%@ 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>

DbHelper.cs used to generate list

    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;
        }
    }
}
Harry Tipper
  • 75
  • 3
  • 10

0 Answers0