Click here to Skip to main content
15,907,328 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
in my GridView paging 10 pages in my grid when ever click the 1,2,3,4, ---10 pages when ever click the grid pages foreword in 1,2,3, when ever click the 2nd page i am getting this error.
Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. To allow pages to override application request validation settings, set the requestValidationMode attribute in the httpRuntime configuration section to requestValidationMode="2.0". Example: <httpruntime requestvalidationmode="2.0" />. After setting this value, you can then disable request validation by setting validateRequest="false" in the Page directive or in the <pages> configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case. For more information, see http://go.microsoft.com/fwlink/?LinkId=153133.


aspx page.

ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" CodeBehind="Answers.aspx.cs" Inherits="Answers" MasterPageFile="~/AdminDetails.Master"  %>

<asp:Content ID="content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <form id="form1" runat="server">
    <div>
    <asp:GridView ID="grdView" runat="server" AutoGenerateColumns="False" 
            AllowPaging="True" AllowSorting="True" onrowediting="grdView_RowEditing" 
            onrowcancelingedit="grdView_RowCancelingEdit" 
            onrowupdating="grdView_RowUpdating" EnableModelValidation="False">
    <columns>
    <asp:BoundField DataField="ID" HeaderText="Question No" />
    <asp:BoundField DataField="Description" ReadOnly="true" HeaderText="Question" />
    <asp:BoundField DataField="Answer" ReadOnly="true" HeaderText="Answer" />
        <asp:TemplateField HeaderText="Comments">
            <edititemtemplate>
                <%--<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Comments") %>'>--%>
            </edititemtemplate>
            <itemtemplate>
               <%-- <asp:Label ID="Label1" runat="server" Text='<%# Bind("Comments") %>'>--%>
                <asp:TextBox ID="txtComments" runat="server" Text='<%# Bind("Comments") %>'>
            </itemtemplate>
        
        <asp:TemplateField HeaderText="Marks">
            <edititemtemplate>
              <%--  <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Marks") %>'>--%>
            </edititemtemplate>
            <itemtemplate>
              <%--  <asp:Label ID="Label2" runat="server" Text='<%# Bind("Marks") %>'>--%>
                <asp:TextBox ID="txtMarks" runat="server" Text='<%# Bind("Marks") %>'>
            </itemtemplate>
        
    
    </columns>
      
    
  
    <br />
        <asp:Label ID="lblmessage" runat="server" Text="Message">
        <br />
        <br />
         <asp:Button ID="Button1" runat="server" Height="33px" 
            onclick="Button1_Click" Text="UPDATE" Width="72px" />
        <br />
        <br />
                                                                                                                                                                                            
  
  TotalMarks:<asp:Label ID="lbltotal"  align="right" runat="server">
    </div>
    </form>
Posted
Updated 10-Jan-12 0:57am
v6
Comments
E.F. Nijboer 10-Jan-12 6:29am    
Did you already check out the link? http://go.microsoft.com/fwlink/?LinkId=153133
Karthik Harve 10-Jan-12 6:30am    
How you are handling gridview page index changed event..?? show that code..
Karthik Harve 10-Jan-12 6:45am    
[Edit] pre tags added.

Hi,

The error message clearly has the solution too :)

disable request validation by setting validateRequest="false" in the Page directive or in the <pages> configuration section.


Like below:

<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest = "false"


This error is mostly occured when there are tags in your text field.
ASP.Net By default validates all input controls for potentially unsafe contents that can lead to Cross Site Scripting and SQL Injections. Thus it disallows such content by throwing the above Exception. By default it is recommended to allow this check to happen on each postback.But its better to check in your grid view, that whether you have any input text like '<' or '>'.

Hope this helps...
 
Share this answer
 
write this code to page index changing

C#
Gridview1.PageIndex=e.NewPageIndex
BindGrid();

..here write the code to bindgrid
 
Share this answer
 
v3
Comments
2011999 10-Jan-12 7:26am    
e.NewPage No intelegence not working
Hi Friend ,

you need to handle the pageindexchanging event.

like below code:

public void gridview_onPageindexchanging(Object Sender,griviewEventArgs e)
{
// you have to handle the above event and set new index
gridview.currentpageindex = e.newpageindex;
BindData();

}
 
Share this answer
 
Comments
2011999 10-Jan-12 11:27am    
gridview.currentpageindex = e.newpageindex;

no intelegence
You have given a input to your application which is treated as risk to the explorer.
This hapend when input value starting with "<" or ">" so it can be interpreted as risk
Solution:
if not removing values staring with "<" (I like something like "<select value>" then try this
Disable request validation by the adding the attribute ValidateRequest="false" to the @ Page directive.
It is on beging of aspx page, staring with
<%@ Page Language …
Example:
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" CodeFile="Default.aspx.cs" Inherits="PandoraPage" %>
 
Share this answer
 
v2
This happens most of the times because of the javascript code or like wise scripting language. You can avoid this by

1) single page

<%@ Page validateRequest="false" %>


2) for whole solution (place it to the web.config file inside the configuration section)

<configuration>
   <system.web>
      <pages validaterequest="false" />
   </system.web>
</configuration>


do not fear use it and if this helps do not hesitate to mark as solved solution.
 
Share this answer
 
v3
protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
   {
       GridView2.PageIndex = e.NewPageIndex;
       PendingBindApproval();
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900