Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
when i want to generate pdf file from rendered page then i got following exception.

RegisterForEventValidation can only be called during Render();

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: RegisterForEventValidation can only be called during Render();

Source Error:

Line 52: RenderControl(htmlTextWriter); <-- I got exception here
Line 53: Response.Write(stringWriter.ToString());
Line 54: Response.End();
Posted
Updated 8-Jun-22 22:09pm
v2
Comments
[no name] 9-Aug-11 9:55am    
What control are you using?

Remember we are not sitting at your desk, working on the same project. Explain the situation completely.
uvp_07ce41 10-Aug-11 0:24am    
Response.Clear(); //this clears the Response of any headers or previous output
Response.Buffer = true; //make sure that the entire output is rendered simultaneously


Response.ContentType = "application/pdf";
StringWriter stringWriter = new StringWriter(); //System.IO namespace should be used

HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);


RenderControl(htmlTextWriter);
Response.Write(stringWriter.ToString());
Response.End();








above is my button click code. when i click on button then i want pdf of rendered page i cant get it.

I don't know about your code. Based on the error message I found this fix link

RegisterForEventValidation can only be called during Render()[^]
 
Share this answer
 
<%@ Page Language="C#" MasterPageFile="~/ABs6ui56nfwdM/AdminMaster.master" StylesheetTheme="mySkin" AutoEventWireup="true"
CodeFile="AdminCoin_Payment.aspx.cs" Inherits="Smb430Adm40n_AdminCoin_Payment" Title="Admi Coin Payment"%>

<asp:content id="Content1" contentplaceholderid="ContentPlaceHolder1" runat="Server">






<asp:image id="Image2" runat="server" imageurl="../UserPanel_Images/printer.png" width="18px">

<asp:linkbutton id="LinkButton1" runat="server" cssclass="Uparmenu" font-bold="False"
="" font-names="Verdana" onclientclick="return CallPrint('divPrint')" style="font-size:12px;position: relative;top: 1px;font-weight: 600;color: #234c76;">Print

 
<asp:image id="Image3" runat="server" imageurl="../UserPanel_Images/excel.png" width="18px">

<asp:linkbutton id="LinkButton3" runat="server" cssclass="Uparmenu" font-bold="False"
="" font-names="Verdana" onclick="btnexporttoexport_Click" style="font-size:12px;position: relative;top: 1px;font-weight: 600;color: #234c76;">Export to Excel








From Date:
<asp:textbox id="txtFromDate" runat="server" maxlength="12" cssclass="ComposeTxtBx" autocomplete="Off">


To Date:
<asp:textbox id="txtToDate" runat="server" maxlength="12" cssclass="ComposeTxtBx" autocomplete="Off">


Select one:
<asp:dropdownlist id="DDLDownPos" runat="server" autopostback="True" cssclass="ComposeTxtBx"
="" onselectedindexchanged="DDLDownPos_SelectedIndexChanged">
<asp:listitem>All
<asp:listitem value="Buyer_name">Member ID
<asp:listitem value="txn_id">Transaction Id
<asp:listitem value="amount1">Amount
<asp:listitem value="currency2">Currency
<asp:listitem value="Status_text">Status





<asp:dropdownlist id="DDLFillItems" runat="server" cssclass="ComposeTxtBx blnk-input" visible="False">
<asp:textbox id="txtSearch" runat="server" cssclass="ComposeTxtBx blnk-input" maxlength="30" text="" visible="False" autocomplete="off">




<asp:button id="btnSearch" runat="server" cssclass="OuterBtn blnk-input" onclick="btnSearch_Click" text="Submit" causesvalidation="False">










Total Records Found: <asp:label id="lblTotRec" runat="server" font-names="Verdana" font-size="12px">



<asp:label id="lblTotalData" runat="server" forecolor="Red" font-bold="true" font-size="15px">



<%=PageNo%>
-
<%=Pagesize %>
of

 
<asp:dropdownlist id="ddlJumpToPage" runat="server" autopostback="true" font-names="Verdana"
="" font-size="11px" onselectedindexchanged="PageChanged" width="58px" cssclass="ComposeTxtBx">




<asp:label id="lblMsg" runat="server" forecolor="Red">






<asp:gridview id="GvCaptchaWork" runat="server" font-bold="False" font-names="verdana"
="" autogeneratecolumns="False" showfooter="True" onrowdatabound="GvCaptchaWork_RowDataBound" cssclass="table-responsivesrptcp">
<columns> <asp:templatefield headertext="SrNo.">
<itemtemplate>
<%# Container.DataItemIndex +1 %>
.

<controlstyle width="100px">
<headerstyle horizontalalign="Center" width="50px">
<itemstyle horizontalalign="Center" width="50px">

<asp:templatefield headertext="Member Id">
<itemtemplate>
<%-- <%# DataBinder.Eval(Container.DataItem, "NAME")%>--%>

<%# DataBinder.Eval(Container.DataItem, "Buyername")%>

<%# DataBinder.Eval(Container.DataItem, "itemname")%>
<%-- Delete --%>

<headerstyle horizontalalign="Center">
<itemstyle horizontalalign="Center">

<asp:templatefield headertext="Transaction Id">
<itemtemplate>


<%# DataBinder.Eval(Container.DataItem, "txnid")%>


Merchant Id: <%# DataBinder.Eval(Container.DataItem, "Merchant")%>

<headerstyle horizontalalign="Center">
<itemstyle horizontalalign="Center">





<asp:templatefield headertext="Amount">
<itemtemplate>
<%--<%# DataBinder.Eval(Container.DataItem, "Amount")%>--%>
<%# Eval("Amt")%>

Amt2: <%# Eval("TotAmt")%>

<headerstyle horizontalalign="Center">
<itemstyle horizontalalign="Center">



<asp:templatefield headertext="Currency">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "currency2")%>


Currency1: <%# DataBinder.Eval(Container.DataItem, "currency1")%>



<headerstyle horizontalalign="Center">
<itemstyle horizontalalign="Center">

<asp:templatefield headertext="Status">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "Status")%>



Status: <%# DataBinder.Eval(Container.DataItem, "Statustext")%>



<headerstyle horizontalalign="Center">
<itemstyle horizontalalign="Center">

<asp:templatefield headertext="Transaction Date">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "TransDate")%>


Update Date: <%# DataBinder.Eval(Container.DataItem, "UpdateDate")%>


<headerstyle horizontalalign="Center">
<itemstyle horizontalalign="Center">

<asp:templatefield headertext="Paid Amt">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "PaidAmt")%>


Paid Amt2: <%# DataBinder.Eval(Container.DataItem, "PaidTotAmt")%>


<headerstyle horizontalalign="Center">
<itemstyle horizontalalign="Center">

<asp:templatefield headertext="Confirm Trans">
<itemtemplate>


<%# DataBinder.Eval(Container.DataItem, "Cnfirmtns")%>


Fee: <%# DataBinder.Eval(Container.DataItem, "Fee")%>

<headerstyle horizontalalign="Center">
<itemstyle horizontalalign="Center">




<emptydatatemplate>
---!!! Ooops,Deposit History Detail Not Found !!!---











<%-- --%>













<asp:image id="Image1" runat="server" imageurl="../UserPanel_Images/printer.png" width="18px">
 
<asp:linkbutton id="btnPrint" runat="server" cssclass="Uparmenu" font-bold="False"
="" font-names="Verdana" onclientclick="return CallPrint('divPrint')" style="font-size:12px;position: relative;top: -4px;font-weight: 600;color: #234c76;">Print

   
<asp:image id="Image4" runat="server" imageurl="../UserPanel_Images/excel.png" width="18px">
 
<asp:linkbutton id="LinkButton2" runat="server" cssclass="Uparmenu" font-bold="False"
="" font-names="Verdana" onclick="btnexporttoexport_Click" style="font-size:12px;position: relative;top: -4px;font-weight: 600;color: #234c76;">Export to Excel
--%>

<%-- <asp:imagebutton id="btnPrint" runat="server" imageurl="../UserPanel_Images/printer.png" width="20px" onclientclick="return CallPrint('divPrint')"> Print
 
<asp:imagebutton id="btnexporttoexport" runat="server" imageurl="../UserPanel_Images/excel.png" width="20px" onclick="btnexporttoexport_Click"> Export to Excel
--%>

<%--





















From :   To :   Select one:<%--DDLDownPos--%>


























function CallPrint(strid) {
var prtContent = document.getElementById(strid);
var WinPrint = window.open('', '', 'letf=0,right=0,top=0,width=790,height=2000,toolbar=0,scrollbars=1,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
prtContent.innerHTML = strOldOne;
}

$(function () {
$("#<%=txtFromDate.ClientID%>").datepicker(
{
dateFormat: 'dd/mm/yy'

});
});

$(function () {

$("#<%=txtToDate.ClientID%>").datepicker(
{
dateFormat: 'dd/mm/yy'

});
});



.ontop {
z-index: 999;
width: 100%;
height: 100%;
top: 0;
left: 0;
display: none;
position: fixed;
overflow: auto;
background-color: #cccccc;
color: #aaaaaa;
opacity: .9;
filter: alpha(opacity = 70);
}
#popup {
width: 300px;
height: 200px;
position: absolute;
color: #ffffff;
background-color: #ec9806;
border-top: black thin solid;
border-right: black thin solid;
border-bottom: black thin solid;
border-left: black thin solid;
/* To align popup window at the center of screen*/
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -150px;
}


function openPopup(div) {
document.getElementById('popupdiv').style.display = 'block';
document.getElementById('<%=HdnInvestId.ClientID %>').value = div;
document.getElementById('sptxt').innerHTML = "InvestmentID: " + div;

}
function hide() {
document.getElementById('popupdiv').style.display = 'none';
document.getElementById('popupdiv').style.display = 'none';
}
//To detect escape button
document.onkeydown = function (evt) {
evt = evt || window.event;
if (evt.keyCode == 27) {
hide();
}
};


function ConfirmDelete() {

if (document.getElementById('<%=MyName.ClientID %>').value != "") {
if (confirm("Are you sure you want to delete this investment ID?")) {
return true;
}
return false;
}
else {
alert("Please enter administrator password !");
return false;
}
}
function Mesag(msg) {
document.getElementById('<%=lblMsg.ClientID %>').innerHTML = msg;
}

 
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