ラベル postbacks の投稿を表示しています。 すべての投稿を表示
ラベル postbacks の投稿を表示しています。 すべての投稿を表示

2012年3月28日水曜日

Resetting Scroll Position on AJAX partial postbacks

I'm sure someone has seen this one before:

    I have a grid inside an UpdatePanel displaying data that requires users to scroll to see the last couple of rows

    When a user selects a row in the grid, and AJAX post fires and displays data at the top of the page, but the scroll position is maintained and the user is required to scroll up to to the top of the page manually.

I need to reset the scroll position to 0,0 when a record is selected in my grid. If anyone can shed some light on this one I would greatly appreciate it.

Thanks

PS

Please see my post here:

http://forums.asp.net/t/1196152.aspx


Thank you - perfect solution, and so little code. I knew it wouldn't take much.

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.

Response.Redirect on asynchronous postback issue with MasterPage

Hello,

So far Atlas seems to handle Response.Redirects correctly during asynchronous postbacks for me, but I have come accross an issue now (I'm using the April CTP):

I have an asp:Button on a MasterPage inside an atlas:UpdatePanel. When the button is clicked an asynchronous postback happens. On the server I handle the button click event and raise a public event called Update that I defined on the MasterPage. A content page using this MasterPage can attach a handler to this Update event in its Page Load event handler or OnLoad override (the content pages have the MasterType directive set so the event can be accessed through the Master property of the Page) and this handler on the content page can perform whatever updates it likes, like re-databind a GridView (this handler must then also invoke Update on the UpdatePanel containing the GridView). This works fine. But if a handler for this Update event in a content page invokes Response.Redirect, then I get problems. The redirect takes place, but when the new page loads it cannot access any if its Page properties like Request, Response, Session, Application, etc. They all give Null Reference exceptions. After this it seems like the web application has restarted.

So, I think this is an Atlas problem. Whereas Atlas handles Response.Redirects ok during asynchronous postbacks when invoked in a handler on the server of a control event where the handler and control are in the same page, it seems to have a problem when invoked in a method on a content page where the asynchronous postback was initiated by a control in a masterpage. Can anybody in the Atlas development team comment on this and reproduce it and suggest a fix?

I can post a code sample if my explanation is not clear.

If you're wondering why a have this button in a master page that can trigger updates in its content pages, that's because I have a web application where I have one main window from where other pages can be opened in new windows. Any of these newly opened windows must be able to trigger an update in the main window. They can do this programmatically using clientside javascript by calling the click method on the button that is part of the master page in the main window where the main window can be accessed from the newly opened window through the window.opener property. Hope this clarifies what I'm trying to achieve: basically a cross-window trigger for update panels.

kind regards,


Remco

please ignore my post. The target page of the Response.Redirect did not work because I had passed it an incorrect url. The url was something like ~/page.aspx??var=value. It didn't like the double ??. I don't blame it. So no Atlas related issue at all. My fault.

Remco