Sys.WebForms.PageRequestManagerParserErrorException : 서버에서받은 메시지를 구문 분석 할 수 없습니다.
내 페이지에 그리드보기가 있고이를 Excel 시트로 내보내고 싶습니다. 아래는이 작업을 수행하기 위해 작성한 코드입니다. 여기에서는 이미 데이터 세트를 그리드를 바인딩하는 방법에 전달하고 btnExcelExport
있으며 버튼입니다. 그리드 콘텐츠를 Excel 시트로 내 보냅니다.
private void BindGridView(DataSet ds)
{
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
GVUserReport.DataSource = ds;
GVUserReport.DataBind();
btnExcelExport.Visible = true;
}
}
}
protected void btnExcelExport_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition","attachment;filename=FileName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GVUserReport.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
return;
}
이제 디버깅 할 때 그리드가 성공적으로 바인딩되었음을 발견했지만 Excel로 내보내려고 할 때 다음 오류가 발생합니다.
"Microsoft JScript 런타임 오류 : Sys.WebForms.PageRequestManagerParserErrorException : 서버에서받은 메시지를 구문 분석 할 수 없습니다."
이 문제를 해결했습니다. 을 사용 하면서 페이지 이벤트 UpdatePanel
에서 아래 코드를 추가 Page_Load
했으며 저에게 효과적이었습니다.
protected void Page_Load(object sender, EventArgs e) {
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(this.btnExcelExport);
//Further code goes here....
}
제 경우 에는 웹 사이트의 마스터 페이지 (코드 숨김) 에서 일부 Response.Write 명령 으로 인해 문제가 발생했습니다 . 그들은 디버깅 목적으로 만 거기에있었습니다 (가장 좋은 방법은 아닙니다) ...
1- Response.Write를 사용 하지 마십시오 .
2- LinkButton을 (동적으로) 생성 한 후 (Page_Load가 아닌) 아래 코드를 넣고 내 문제를 해결했습니다.
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(lblbtndoc1);
내 VB.Net 친구-
Dim scriptManager As ScriptManager = scriptManager.GetCurrent(Me.Page)
scriptManager.RegisterPostBackControl(Me.YourButtonNameHere)
Triggers
업데이트 패널 의 태그에 컨트롤을 추가했습니다 .
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="exportLinkButton" />
</Triggers>
</asp:UpdatePanel>
이렇게하면 exportLinkButton이 UpdatePanel을 트리거하여 업데이트합니다. 여기에
더 많은 정보가 있습니다 .
나는 같은 오류가 있었고 AsyncPostBackTrigger<asp:PostBackTrigger ControlID="xyz"/>
대신 시도 했습니다. 부분 포스트 백을 원하지 않기 때문입니다.
Add this to you PageLoad and it will solve your problem:
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(this.lblbtndoc1);
This worked for me too, but with an addition (below).
protected void Page_Load(object sender, EventArgs e) {
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(this.btnExcelExport);
//Further code goes here....
}
I was registering a script on my button to click on another button after its event was finished processing. In order for it to work, I had to remove the other button from the Update Panel (just in case somebody faces the same problem).
What worked for me was setting aspnet:MaxHttpCollectionKeys to a high value on appSettings tag on the inetpub VirtualDirectories\443\web.config file:
<configuration>
<appSettings>
<add key="aspnet:MaxHttpCollectionKeys" value="100000" />
</appSettings>
</configuration>
ReferenceURL : https://stackoverflow.com/questions/11221033/sys-webforms-pagerequestmanagerparsererrorexception-the-message-received-from-t
'Nice programing' 카테고리의 다른 글
다른 테이블이 아닌 한 테이블에서 선택 (0) | 2020.12.26 |
---|---|
HTML을 사용한 PHP 단순 foreach 루프 (0) | 2020.12.26 |
Robolectric으로 조각을 어떻게 테스트 할 수 있습니까? (0) | 2020.12.26 |
Bootstrap Modal에서 닫기 이벤트 캡처 (0) | 2020.12.26 |
tabindex를 무시하는 Safari (0) | 2020.12.26 |