In my gridview wheree records are displayed, I have a column where there is a linkbutton to view the details of record in that row, and also a button at the top of the Gridview
where I can type into the serach box and click search button to display only the search record in that Gridview. But I do either of these, I get this error
HTTP Error 413.1 - Request Entity Too Large The request filtering module is configured to deny a request that exceeds the request content length.
I have added the following to my web.confg file but it doesn't work
The surprising thing is that when the same Gridview displays less record (like 3 records), the error will not occur. But when I have more than 5 records display, the error occurs
<system.web>
<httpRuntime targetFramework="4.7.2" maxRequestLength="3145728" maxQueryStringLength="32768" maxUrlLength="65536" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxQueryString="32768"/>
</requestFiltering>
</security>
</system.webServer>
HTML
<asp:UpdatePanel ID="panel" runat="server" ChildrenAsTriggers="true">
<ContentTemplate>
<div class="container-fluid p-3 mb5 bg-white rounded" id="card" style="margin: 0 auto; padding: 10px; border: 1.3px solid #e4e7e8;">
<div class="grid-corner" style="width: 100%; background-color: white; font-size: 9pt; margin: 0 auto; padding: 10px;">
<div class="input-group col-sm-6" style="padding: 5px; float: right; border-radius: 5px; margin-bottom: 1%;">
<asp:TextBox ID="Searchbox" runat="server" placeholder="Recipient Name" CssClass="form-control" Font-Size="10pt"></asp:TextBox>
<div class="input-group-append">
<asp:Button ID="Button1" runat="server" CssClass="btn btn-primary" Text="Search" OnClick="Btnsearch" />
</div>
</div>
<asp:GridView ID="GridView1" runat="server" GridLines="None" DataKeyNames="Id" AllowPaging="true" HeaderStyle-BackColor="#fdfdfd" HeaderStyle-Font-Bold="false" HeaderStyle-ForeColor="#05214d" HeaderStyle-Font-Size="10pt" Font-Size="9pt"
AutoGenerateColumns="false" OnRowDataBound="OnRowDataBound" HeaderStyle-HorizontalAlign="left" RowStyle-HorizontalAlign="Left" OnPageIndexChanging="OnPageIndexChanging" class="table" Width="100%">
<EmptyDataTemplate>
<div style="text-align: center; font-weight: 500; margin-top: 2%;">
<i class="fal fa-file-times" style="margin: 0 auto; font-size: 30pt; color: #145c7c;"></i>
<p id="P1" runat="server" style="font-size: 11pt; font-weight: 400;">No Recipient</p>
</div>
</EmptyDataTemplate>
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="checkAll" runat="server" onclick="SelectAll(this)" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckSelected" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Id" HeaderText="ID" HeaderStyle-Font-Bold="false" />
<asp:BoundField DataField="Recipient" HeaderText="Recipients" HeaderStyle-Font-Bold="false" />
<asp:TemplateField HeaderText="Email" HeaderStyle-Font-Bold="false">
<ItemTemplate>
<asp:HyperLink ID="emailLink" runat="server" Text='<%# Eval("RecEmail") %>' NavigateUrl='<%# Eval("RecEmail", "mailto:{0}") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID="hfSeq" Value='<%# Eval("Data") != System.DBNull.Value ? Convert.ToBase64String((byte[])Eval("Data")) : string.Empty %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="AwardDate" HeaderText="Date" HeaderStyle-Font-Bold="false" />
<asp:BoundField DataField="Reference" HeaderText="Reference" HeaderStyle-Font-Bold="false" />
<asp:TemplateField HeaderText="Action" HeaderStyle-Font-Bold="false">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lbDetail" Text="view" OnClick="CmdEdit_Click" ForeColor="SteelBlue" data-ID='<%# Eval("Id") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div style="float: right; font-size: 10pt; margin-right: 1%;">
Showing Page
<asp:Label ID="lblPageIndex" runat="server" Text="Label" />
of
<asp:Label ID="lblTotalPage" runat="server" />
(<asp:Label ID="lblTotal" runat="server" />
Records)
<div class="dvPager">
<asp:Repeater ID="rptPager" runat="server">
<ItemTemplate>
<asp:LinkButton ID="lnkPage" runat="server" Text='<%#Eval("Text") %>' CommandArgument='<%# Eval("Value") %>'
CssClass='<%# Convert.ToBoolean(Eval("Enabled")) ? "page_enabled" : "page_disabled" %>'
OnClick="Page_Changed" OnClientClick='<%# !Convert.ToBoolean(Eval("Enabled")) ? "return false;" : "" %>'></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
</div>
</div>
<br />
<br />
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
GetCertDataGrid();
}
}
public void GetCertDataGrid()
{
string constr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM DocTable WHERE AwardDate=@AwardDate ORDER BY Id DESC"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Parameters.AddWithValue("@AwardDate", Session["certInfo"]);
cmd.Connection = con;
sda.SelectCommand = cmd;
con.Open();
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
ViewState["dt"] = dt;
GridView1.DataSource = dt;
GridView1.DataBind();
}
con.Close();
}
}
}
this.GetDocRecipient(1);
}
int PageSize = 10;
private void GetDocRecipient(int pageIndex)
{
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
try
{
using (SqlCommand cmd = new SqlCommand("DocRecipient", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@CreatedBy", createby.Text.Trim());
cmd.Parameters.AddWithValue("@AwardDate", Session["certInfo"]);
cmd.Parameters.AddWithValue("@PageIndex", pageIndex);
cmd.Parameters.AddWithValue("@PageSize", PageSize);
cmd.Parameters.Add("@RecordCount", SqlDbType.Int, 4);
cmd.Parameters["@RecordCount"].Direction = ParameterDirection.Output;
con.Open();
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
using (SqlDataReader dr = cmd.ExecuteReader())
if (dr.HasRows)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
else
{
}
int recordCount = Convert.ToInt32(cmd.Parameters["@RecordCount"].Value);
this.PopulatePager(recordCount, pageIndex);
}
}
con.Close();
}
}
catch (SqlException ex)
{
string msg = "Error:";
msg += ex.Message;
throw new Exception(msg);
}
}
}
protected void Page_Changed(object sender, EventArgs e)
{
int pageIndex = int.Parse((sender as LinkButton).CommandArgument);
this.GetDocRecipient(pageIndex);
}
private void PopulatePager(int recordCount, int currentPage)
{
double dblPageCount = (double)((decimal)recordCount / (decimal)PageSize);
int pageCount = (int)Math.Ceiling(dblPageCount);
List<System.Web.UI.WebControls.ListItem> pages = new List<System.Web.UI.WebControls.ListItem>();
if (pageCount > 0)
{
if (currentPage != 1)
{
pages.Add(new System.Web.UI.WebControls.ListItem("Prev", (currentPage - 1).ToString()));
}
if (pageCount < 4)
{
for (int i = 1; i <= pageCount; i++)
{
pages.Add(new System.Web.UI.WebControls.ListItem(i.ToString(), i.ToString(), i != currentPage));
}
}
else if (currentPage < 4)
{
for (int i = 1; i <= 4; i++)
{
pages.Add(new System.Web.UI.WebControls.ListItem(i.ToString(), i.ToString(), i != currentPage));
}
pages.Add(new System.Web.UI.WebControls.ListItem("...", (currentPage).ToString(), false));
}
else if (currentPage > pageCount - 4)
{
pages.Add(new System.Web.UI.WebControls.ListItem("...", (currentPage).ToString(), false));
for (int i = currentPage - 1; i <= pageCount; i++)
{
pages.Add(new System.Web.UI.WebControls.ListItem(i.ToString(), i.ToString(), i != currentPage));
}
}
else
{
pages.Add(new System.Web.UI.WebControls.ListItem("...", (currentPage).ToString(), false));
for (int i = currentPage - 2; i <= currentPage + 2; i++)
{
pages.Add(new System.Web.UI.WebControls.ListItem(i.ToString(), i.ToString(), i != currentPage));
}
pages.Add(new System.Web.UI.WebControls.ListItem("...", (currentPage).ToString(), false));
}
if (currentPage != pageCount)
{
pages.Add(new System.Web.UI.WebControls.ListItem("Next", (currentPage + 1).ToString()));
}
}
rptPager.DataSource = pages;
rptPager.DataBind();
lblPageIndex.Text = currentPage.ToString();
lblTotalPage.Text = ((recordCount / PageSize) + ((recordCount % PageSize) > 0 ? 1 : 0)).ToString();
lblTotal.Text = recordCount.ToString();
}
protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
this.GetDocRecipient(1);
}
private void Getsearch()
{
try
{
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT Id, Recipient, RecEmail, Data, AwardDate, Reference FROM DocTable WHERE Recipient LIKE '%' + @Recipient + '%'";
cmd.Parameters.AddWithValue("@Recipient", Searchbox.Text.Trim());
cmd.Connection = con;
con.Open();
DataTable dt = new DataTable();
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
con.Close();
}
}
}
catch (SqlException ex)
{
string msg = "Error:";
msg += ex.Message;
throw new Exception(msg);
}
}
protected void Btnsearch(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Searchbox.Text.Trim()))
{
this.Getsearch();
}
else
{
string message = "alert('Empty Search')";
ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", message, true);
Searchbox.Text = "";
this.GetDocRecipient(1);
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[1].Visible = false;
e.Row.Cells[6].Visible = false;
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].Visible = false;
e.Row.Cells[6].Visible = false;
}
}
protected void CmdEdit_Click(object sender, EventArgs e)
{
LinkButton button = (LinkButton)sender;
var DocID = (string)button.Attributes["data-ID"];
Session["DocID"] = DocID;
Response.Redirect("documentdetails.aspx");
}