Showing posts with label partial. Show all posts
Showing posts with label partial. Show all posts

Wednesday, March 28, 2012

How Do I Reset Scroll Position Inside UpdatePanel?

Hello,

I have a UserControl inside an UpdatePanel. The UserControl contains several DIVs that I show and hide through partial postback. I want the contents of each DIV to be scrolled to the top when I show it. I have tried using the ScriptManager to set focus onto the topmost control of each DIV when I show it, but it doesn't work. I have also tried through javascript to no avail. I know this is kind of the opposite of the behavior that many folks want from AJAX, but I need it for this piece of my application. I have tried searching but all examples are page-centric, not usercontrol-centric and speak to SmartNavigation.

Any help is appreciated.

Brendan

not sure if this would help, but I found something interestingin terms of firing off some js code during a partial page update :

http://ajax.asp.net/docs/ClientReference/Sys.WebForms/PageRequestManagerClass/default.aspx

It was particularly useful for displaying a message to the user to indicate something was happening...

Good luck,

Bob


I ended up just using this in the codebehind of the ascx:

ScriptManager.RegisterStartupScript(Page,typeof(PageTemplate),"Focus","focus();",true);

And including this function in a .js file (one line for each section):

function focus() {
try { window.location.href='#IA'; } catch (err) {}
try { window.location.href='#IB'; } catch (err) {}
try { window.location.href='#IC'; } catch (err) {}
try { window.location.href='#ID'; } catch (err) {}
try { window.location.href='#IIA'; } catch (err) {}
try { window.location.href='#IIB'; } catch (err) {}
try { window.location.href='#IIC'; } catch (err) {}
}

Seems to work on all but the initial page change, which is 'good enough' for me at this stage.

Saturday, March 24, 2012

How can I use updatepanel to do a partial page update of the contents of a division (div).

Hello,

I am new to AJAX and know I must be missing the obvious with this question. I would like to dynamically change the HTML content between opening and closing HTML DIV tag. The partial page update examples that I have seen, update controls rather than content such as HTML with in a division. The example used to illustrate the problem is trivial. In my actual application, the updated content will actually come from a database and include HTML tags.

Thanks in advance for your assistance.

The following steps lead to an example of my question:

    Start a new AJAXEnabled Web Application using Visual Studio 2005.

    In design mode, drag an Updatepanel from the AJAX Extensions tools to the designer.

    Drag a DIV from the HTML Tools to the Updatepanel.

    Drag a Button from the Standard Tools to the Updatepanel, but outside the DIV box.

    Switch from Design to Source Mode and type the following line between the Opening and Closing Div tags:
    This is the link displayed when the page is loaded: <ahref="http://www.someplace.com">someplace</a><br/>

    Switch from Source Mode Back to Design Mode and observe that there is a line of text ending with a hyperlink in the DIV element box reading "This is the link displayed when the page is loaded: someplace". (someplace is a hyperlink)How do I code the button click event to change the content between the opening and closing DIV tag. For example, suppose I the following to be displayed: "This is a different link: somewhere else". (somewhere else is a hyperlink)

Here is all of the generated code up to and including step 6:

<%@dotnet.itags.org.PageLanguage="vb"AutoEventWireup="false"CodeBehind="Default.aspx.vb"Inherits="AJAXEnabledWebApplication1._Default" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

</head>

<body>

<formid="form1"runat="server">

<asp:ScriptManagerID="ScriptManager1"runat="server"/>

<div>

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

<divstyle="width: 160px; height: 100px">

This is the link displayed when the page is loaded:<ahref="http://www.someplace.com">someplace</a><br/>

</div>

<asp:ButtonID="Button1"runat="server"Text="Button"OnClick="Button1_Click"/>

</ContentTemplate>

</asp:UpdatePanel>

</div>

</form>

</body>

</html>

Looks like duplicate post

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