I got the same error. First i change EnableEventValidation to false but it didnt solve my problem as i want. Then i try to fix it with adding isnotpostback but it didnt work too. In my case i have a combobox. This combobox can only be seen by users which
have the wright role. So if a user who hasnt got this role enters there is no error. But when a user who has it enters and choose the items in combobox then
click the button to insert data THE ERROR COMES UP :( . Maybe i put it in wrong place. Could anyone look at my code and say that it is true or not? and also please look for what can i differently do for this problem in my case.
Thanks.
Here is my page load event:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["uyedurum"] == null)
{
Response.Redirect("sbo.aspx");
}
if ((int)Session["rol"] == 3)
{
SqlConnection conn = new SqlConnection(strConnString);
SqlDataAdapter ad = new SqlDataAdapter("Select * from ST$Sirketler", conn);
DataSet ds = new DataSet();
ad.Fill(ds);
if (!IsPostBack)
{
ddlSirketler.DataSource = ds;
ddlSirketler.DataTextField = "SirketAdi";
ddlSirketler.DataValueField = "sirketid";
ddlSirketler.DataBind();
}
lblKullanici.Visible = true;
lblKullanici.Text = "Şirket Kullanıcısı:";
STPanel.Visible = true;
}
else if ((int)Session["rol"] == 7)
{
lblKullanici.Visible = true;
lblKullanici.Text = "Kullanıcı:";
ddlKullanici.Visible = true;
}
switch ((int)Session["rol"])
{
case 2:
case 4:
case 5:
linkOnay.Visible = false;
break;
}
}
I had the same problem. My problem occured when I called the PopulateGrid() in the Page_Load() method, but it only happened then the event which caused the page to reload was triggered from within the grid that got populated, ie.:
Grid got button
-> button clicked (from within grid)
-> run page_load (generate grid)
-> try and find the button_onclick event (it did not exist as the button was recreated with the new grid)
Fixed it like this:
if (!Page.IsCallback && !Page.IsPostBack)
{
PopulateGrid();
}
Haha, sorry for the repost...I did not read all the pages...did not see there were more than the first one.
It surely would have saved me hours of fighting!!
i solved my problem thanks for everything. I had had another mistake so maybe the replacement of ispostback isnt the main problem but i solved it anyway. Thanks again.
I did your recommandation and my program works properly ,but security is very important for me. do you have any suggestion for me that not to decrease security?is there another solution for this problem?
The EnableEventValidation parameter causes ASP.NET to perform a security check on the data being post back. If you do have to disable it because some of your legitimate form data fits into one of their attack patterns, you can implement your own checks too.
elephantman
Member
164 Points
450 Posts
Same Error: i did ispostback but cant solve
Aug 07, 2008 06:44 AM|LINK
I got the same error. First i change EnableEventValidation to false but it didnt solve my problem as i want. Then i try to fix it with adding isnotpostback but it didnt work too. In my case i have a combobox. This combobox can only be seen by users which have the wright role. So if a user who hasnt got this role enters there is no error. But when a user who has it enters and choose the items in combobox then click the button to insert data THE ERROR COMES UP :( . Maybe i put it in wrong place. Could anyone look at my code and say that it is true or not? and also please look for what can i differently do for this problem in my case.
Thanks.
Here is my page load event:
protected void Page_Load(object sender, EventArgs e) { if (Session["uyedurum"] == null) { Response.Redirect("sbo.aspx"); } if ((int)Session["rol"] == 3) { SqlConnection conn = new SqlConnection(strConnString); SqlDataAdapter ad = new SqlDataAdapter("Select * from ST$Sirketler", conn); DataSet ds = new DataSet(); ad.Fill(ds); if (!IsPostBack) { ddlSirketler.DataSource = ds; ddlSirketler.DataTextField = "SirketAdi"; ddlSirketler.DataValueField = "sirketid"; ddlSirketler.DataBind(); } lblKullanici.Visible = true; lblKullanici.Text = "Şirket Kullanıcısı:"; STPanel.Visible = true; } else if ((int)Session["rol"] == 7) { lblKullanici.Visible = true; lblKullanici.Text = "Kullanıcı:"; ddlKullanici.Visible = true; } switch ((int)Session["rol"]) { case 2: case 4: case 5: linkOnay.Visible = false; break; } }and this is my combobox code:
krappies
Member
200 Points
52 Posts
Re: error: enableEventValidation="true"/
Aug 10, 2008 04:55 PM|LINK
Hi
I had the same problem. My problem occured when I called the PopulateGrid() in the Page_Load() method, but it only happened then the event which caused the page to reload was triggered from within the grid that got populated, ie.:
Grid got button
-> button clicked (from within grid)
-> run page_load (generate grid)
-> try and find the button_onclick event (it did not exist as the button was recreated with the new grid)
Fixed it like this:
if (!Page.IsCallback && !Page.IsPostBack)
{
PopulateGrid();
}
Hope this helps someone.
krappies
Member
200 Points
52 Posts
Re: error: enableEventValidation="true"/
Aug 10, 2008 05:02 PM|LINK
Haha, sorry for the repost...I did not read all the pages...did not see there were more than the first one.
It surely would have saved me hours of fighting!!
krappies
Member
200 Points
52 Posts
Re: Same Error: i did ispostback but cant solve
Aug 10, 2008 05:06 PM|LINK
Hi elephantman
You did possibly put the check in the incorrect place, try this code:
protected void Page_Load(object sender, EventArgs e) { if (Session["uyedurum"] == null) { Response.Redirect("sbo.aspx"); } if ((int)Session["rol"] == 3) {if (!IsPostBack) { SqlDataAdapter ad = new SqlDataAdapter("Select * from ST$Sirketler", conn); DataSet ds = new DataSet(); ad.Fill(ds); SqlConnection conn = new SqlConnection(strConnString); ddlSirketler.DataSource = ds; ddlSirketler.DataTextField = "SirketAdi"; ddlSirketler.DataValueField = "sirketid"; ddlSirketler.DataBind(); } lblKullanici.Visible = true; lblKullanici.Text = "Şirket Kullanıcısı:"; STPanel.Visible = true; } else if ((int)Session["rol"] == 7) { lblKullanici.Visible = true; lblKullanici.Text = "Kullanıcı:"; ddlKullanici.Visible = true; } switch ((int)Session["rol"]) { case 2: case 4: case 5: linkOnay.Visible = false; break; } }
elephantman
Member
164 Points
450 Posts
Re: Same Error: i did ispostback but cant solve
Aug 10, 2008 05:50 PM|LINK
thanks for reply my data is at office so tomorrow trying this will be my first job :) i hope it works. thanks again
elephantman
Member
164 Points
450 Posts
Re: Same Error: i did ispostback but cant solve
Aug 11, 2008 12:28 PM|LINK
i solved my problem thanks for everything. I had had another mistake so maybe the replacement of ispostback isnt the main problem but i solved it anyway. Thanks again.
k_nitin_r
Member
346 Points
64 Posts
Re: error: enableEventValidation="true"/
Aug 11, 2008 12:34 PM|LINK
The EnableEventValidation parameter causes ASP.NET to perform a security check on the data being post back. If you do have to disable it because some of your legitimate form data fits into one of their attack patterns, you can implement your own checks too.
ftm
Member
44 Points
133 Posts
Re: Is there a solution?
Oct 15, 2008 02:52 PM|LINK
Hiba
Within your Page_Load event, try wrapping your .Databind() code within a Not.Postback check, something like below:
' Do not execute this code for postbacks to avoid validation errors If Not Page.IsPostBack Then ' Populate Grid GridView1.DataBind() End Ifcodemobile
Member
134 Points
98 Posts
Re: error: enableEventValidation="true"/
Dec 04, 2008 10:49 AM|LINK
If there is no such security matter then
it is not bad to use EnableEventValidation="False" in your application. [:)]
shekar_b
Member
2 Points
1 Post
Re: PROBLEM SOLVE
Jan 30, 2009 12:41 PM|LINK
This fixed it - Thanks.