I'm creating a client insert form, in this form has a <asp:HiddenField/> named Id for save selected client id, but when I try submit form, it is on Page enableEventValidation="true" error, when I rename this HiddenField for any other Id, it's work
<asp:HiddenField runat="server" ID="Id" />
My form can submit success when I set enableEventValidation="false", but maybe I will need it in future
How to can I resolve this problem? keep HiddenField named Id
PrintScreen:
You've pretty much answered your own question. The only way to make this work is set enableEventValidation="false" or rename your HiddenField
Renaming it would be the best solution here, for security reasons
If you're are using framework 4.0 then entry in web.config ()
<configuration>
<system.web>
<pages validateRequest="false" />
</system.web>
</configuration>
If you're using framework 4.5 then entry in web.config (requestValidationMode="2.0")
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" requestValidationMode="2.0"/>
</system.web>
Link
This might not be the solution for your problem, but i was having same problem and solved it by checking for postback before binding data.
(!IsPostBack)
{
binddata(); //this was my gridview binding function
}
This error also occurs when there is another form on the page that does not contain runat = server. Please check if there is another form on the master page or the current page.
Related
For some weird reason when I enter such characters in text fields and press submit button I getting blank page loaded and I don't see any errors appear.
Include requestValidationMode in your web.config file.
<system.web>
...
<httpRuntime requestValidationMode="2.0" />
</system.web>
Also you can set ValidateRequest to false in your page directive.
<%# Page ... ValidateRequest="false" %>
I have a simple aspx page through which i am entering Text into a textbox the text are coming though texteditor so the text are with html tags.
Such as <p>My name</p>
the error which i am getting is like:
Server Error '/' Application
A potentially dangerous Request.Form value was detected from the client (ctl00$ctl00$ContentPlaceHolder1$ContentPlaceHolder2$TxtTopicName="<p>kdarftghjh</p>").
What type of error is this and how could i resolve such error.Thanks for any assistance.
If you're using webforms you can add the following to your page-declaration:
validateRequest="false"
You are having html tags in this input(<,>). just remove it or encode it. of if you really need to do like this try adding following part to web.config
<configuration>
<system.web>
<httpRuntime requestValidationMode="2.0" />
</system.web>
<pages validateRequest="false">
</pages>
</configuration>
I have a registration page with many fields and DDl's when i scroll down and select the ddl value then the page going to top of the page and again i have to scroll to the control and have to select the page.How to control the page by stopping at the control even though the value is changed.
Use MaintainScrollPositionOnPostback="true" in Page directive
Something like this
<%# Page MaintainScrollPositionOnPostback="true" %>
to know more about this Go here.
Alternatively you can, put this in Web.config to make this setting global, By this
<?xml version="1.0"?>
<configuration>
<system.web>
<pages maintainScrollPositionOnPostBack="true">
</pages>
</system.web>
<configuration>
I am working on an MVC site using NHaml for the view engine.
I have a page that needs to submit HTML code as a form value and am getting the System.Web.HttpRequestValidationException thrown at me.
I want to specify the <%# Page validateRequest="false" %> so that this page will allow this data to be submitted but am unsure on how to do this with NHaml generating the pages.
Side note on this:
The editor I was using was TinyMCE and I found that it has an option for encoding the output, that way it doesn't trigger the anti-html validation.
Of course, then your value is encoded so you have to make sure to decode it at the proper time.
See http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/encoding
You may try annotating your controller action with the ValidateInputAttribute:
[ValidateInput(false)]
public ActionResult Index()
{
// ...method body
}
This could also be done in the config file for the whole application:
<configuration>
<system.web>
<pages validateRequest="false" />
</system.web>
</configuration>
I am feeling like an idiot right now, but I cannot for the life of me figure out why I cannot seem to call user controls from within my asp.net webpage. I'm still learning asp.net but I can't find any information from searching on google.
I'm trying to load a specific control on the page when the user presses a linkbutton. So I created an empty user control via the right click menu:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
In other words, I have not touched any part of the created user control. Yet attempting to create this web control and add it to the form seems to not work, as it claims that the WebUserControl class does not exist (I have no other controls in my project):
UserControl blah = new WebUserControls();
produces a "The type or namespace is invalid". Why can none of my asp.net webform pages get the control into scope?
The new control must be added to the site's Web.config file.
<configuration>
<system.web>
<pages>
<controls>
<add tagPrefix="my"
tagName="WebUserControl"
src="~/WebUserControl.ascx"/>
</controls>
</pages>
</system.web>
</configuration>
Use this to place the new control in an .aspx page.
<my:WebUserControl runat="server" ID="MyWebUserControl" />
In addition to registering them one-by-one in web.config, you can also use a <%# Register %> directive in the source of the markup files that reference the control.
Or, you can move your controls into a DLL and include them all by referencing the assembly from your web.config (takes some extra work, though).