2012年3月26日月曜日

Response.Redirect and regular postbacks

I have an updatepanel that includes several controls, and I need to be able to do things such as export to outlook, export to excel and use fileupload controls.

To move those links outside of updatepanels would compromise my layout.

Is there anyway I can force a button to perform a classic postback if it's inside an update panel?

Thanks!Hmmm, interesting. Here's an idea. Could you have a button outside the UpdatePanel with the "visibility:hidden" style set (NOT Visible=False, btw), and then have a button inside the UpdatePanel who's onclick script is "onclick='realPostBackButton.click()". So basically when the user clicks the button inside the UpdatePanel it just triggers a trick outside of it.
thanks for the tip. i could do that. if that's the only workaround possible, then i suppose it isn't too painful.

I can't think of another way to do it, so we'll keep it our little secret. :)


My button is outside of the update pannel and I get errors trying to export to excel. It gives me the following error:

Control 'ctl00_contentPlaceHolder_GridView1' of type 'GridView' must be placed inside a form tag with runat=server.

I think this is because I am using a Master Page with the Ultrapanel. My source for exporting to excel is:

protected

void btnExportToExcel_Click(object sender,ImageClickEventArgs e)

{

Response.Clear();

Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");

Response.Charset = "";

Response.ContentType = "application/vnd.xls";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

GridView1.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();

}

It fails on the RenderControl method. Any ideas?

Thanks,

Duncan


Just what the code says - the Gridview must be within a <form runat="server"> element, either in the MasterPage or in the ContentPanel.

So there is no way to export a gridview that is in an Atlas:UpdatePannel, because my understanding if exists there is will not be in a <form runat="server"> element. If you try to put the <form> element in the ContentPannel of the UpdatePannel then it will conflict with the one in the master page.


The one at the master page should be fine. Something else must be causing the problem - is the ContentPlaceHolder in the Master Page not within the form tag?

Note the SampleWebsite that's included wiht the Toolkit (DefaultMaster.master) has a form tag and the GridView's in the sample pages work correctly.


I ended up using the Interop.Excel dll to export to excel and it worked.

I couldn't get my old method to work but it doesn't appear that it was an ATLAS issue. To get rid of that particular error I had add the following override.

public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for the

}


I am getting 'Unknown Error' and no export. What is the deal?. Is it possible to use Atlas and export to Excel?
Because AJAX is not doing a full post I found that you cannot do an export to excel with Response.Write. What I had to do was save the file to the server, and then do a windows.open in my javascript OnClientClick funtion.

0 件のコメント:

コメントを投稿