Monday, March 26, 2012

prevent refresh between screens

Hi,

I want to prevent refresh between screens.I have menu in the top of screen and when I pass between screens I want that this menu be static and don't refresh.

How can I do it?

Hi Rayak,

If you want the menu on the top to don't refresh when you are opening another webpage it isn't possible. Openening a new page can't stop your menu from flickering. If you want to stop it from refresing when events happen on your page you can use an updatepanel. Put you menu in the updatepanel and asign trigger (controls) to the updatepanel. Hope this helps!

Regards,


I use Master Page .All menu is in Master Page.If I put updatepanel in Master Page ,it doesn't work.

Hi RayaK,

When you are using masterpages and you put your menu in the masterpage this will make it available to al the content pages that deriv e from that master page, but al the content pages are still different aspx pages. When you make a request to defaultB.aspx when you are at defaultA.aspx you are requesting a total new page which means that the menu will be rendered again but on another page (flickering). UpdatePanels are used when you want to update parts of a webpage. You stay at the same webpage but you need to update a part of a webpage. Hope this helps.

Regards,


Hi,

Ok,I understand.Maybe do you know another method how to do it?


Hi RayaK,

No i don't know a solution for this. i think that for now it isn't possbile so your menu will be flickering when you go to another page. SorryWink. Good luck with Ajax development

Regards,


Dennis van de Laar:

Hi RayaK,

No i don't know a solution for this. i think that for now it isn't possbile so your menu will be flickering when you go to another page. SorryWink. Good luck with Ajax development

Regards,

If you have a master page you can use that in the default.aspx. In the default page you can set an update panel arround the content zone with update method set to conditional and having the menu as a trigger. Now, inside the update panel all you need is a dynamic web user control loader that loads a control based on the user menu selection.

I'm pretty sure this architecture works, although I never tested it.

Also, note that approaching the problem in this way is not much different than loading the whole page again. When u wrap all this information in an update panel everything will travel back and forward on the wire...
Using custom AJAX callbacks is much more efficient.


HI DBA,

I disagree with you. The way you describe your solution isn't working. Some very simple test can made. I created 1 masterpage with an scriptmanager and an UpdatePanel. In the updatepanel is a contentplaceholder. I have 2 buttons on the masterpage. One is navigating to Page1 and one is navigating to Page2. Then i created 2 contentpage based on the masterpage. I put on both pages a label in the contentplaceholder which will be set with the name of the page. When i click on the buttons on the masterpage it will build the webpage from scratch, because its a new page.

One thing is true. when i also put a button in the contentplaceholder which will set the label.Text from NAME OF THE PAGE to the CURRENT DATE. This will be done by partial rendering. This is correct because you stay on the same page and you are in the updatepanel which is deployed on the masterpage

MasterPage:

<%

@.MasterLanguage="C#"AutoEventWireup="true"CodeFile="UpdatePanelMasterPage.master.cs"Inherits="Masterpage_UpdatePanelMasterPage" %>

<!

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"></asp:ScriptManager><asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Page1"/><asp:ButtonID="Button2"runat="server"OnClick="Button2_Click"Text="Page2"/><div><asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><asp:contentplaceholderid="ContentPlaceHolder1"runat="server"></asp:contentplaceholder></ContentTemplate></asp:UpdatePanel></div></form>

</

body>

</

html>

ContentPage1:

<%

@.PageLanguage="C#"MasterPageFile="~/Masterpage/UpdatePanelMasterPage.master"AutoEventWireup="true"CodeFile="UpdatePanelMaster.aspx.cs"Inherits="UpdatePanelMaster"Title="Untitled Page" %>

<

asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server"><asp:Buttonid="Button1"runat="server"OnClick="Button1_Click"Text="Button"/><br/><asp:Labelid="Label1"runat="server"Text="Label"></asp:Label>

</

asp:Content>

Code behind:

using

System;

using

System.Data;

using

System.Configuration;

using

System.Collections;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

public

partialclassUpdatePanelMaster : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

this.Label1.Text ="Page1";

}

protectedvoid Button1_Click(object sender,EventArgs e)

{

this.Label1.Text =DateTime.Now.ToString();

}

}

ContentPage2:

<%

@.PageLanguage="C#"MasterPageFile="~/Masterpage/UpdatePanelMasterPage.master"AutoEventWireup="true"CodeFile="UpdatePanelMaster2.aspx.cs"Inherits="UpdatePanelMaster2"Title="Untitled Page" %>

<

asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server"><asp:Labelid="Label1"runat="server"Text="Label"></asp:Label>

</

asp:Content>

Code behind:

using

System;

using

System.Data;

using

System.Configuration;

using

System.Collections;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

public

partialclassUpdatePanelMaster2 : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

this.Label1.Text ="Page2";

}

}

Regards,


Dennis van de Laar:

HI DBA,

I disagree with you. The way you describe your solution isn't working. Some very simple test can made. I created 1 masterpage with an scriptmanager and an UpdatePanel. In the updatepanel is a contentplaceholder. I have 2 buttons on the masterpage. One is navigating to Page1 and one is navigating to Page2. Then i created 2 contentpage based on the masterpage. I put on both pages a label in the contentplaceholder which will be set with the name of the page. When i click on the buttons on the masterpage it will build the webpage from scratch, because its a new page.

One thing is true. when i also put a button in the contentplaceholder which will set the label.Text from NAME OF THE PAGE to the CURRENT DATE. This will be done by partial rendering. This is correct because you stay on the same page and you are in the updatepanel which is deployed on the masterpage

HelloDennis van de Laar,

That wasn't at all what I suggested:

I suggested you to try the following structure:

[MasterPage]
<asp:ScriptManagerID="ScriptManager"runat="server" />
<asp:contentplaceholderid="cphMainContent"runat="server">
</asp:contentplaceholder>

[Default.aspx]

<%@.PageLanguage="C#"MasterPageFile="~/MasterPages/Default.master"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="MasterPages_Default"Title="The dynamic saga" %>

<asp:ContentID="MainContent"ContentPlaceHolderID="cphMainContent"Runat="Server">
<asp:Buttonrunat="server"ID="btnLoadPage1" text="Load page 1"OnClick="btnLoadPage1_Click" />
<asp:UpdatePanelID="UpdPnlMainContent"runat="server">
<Triggers>
<!-- Insert Menu trigger here -->
</Triggers>
<ContentTemplate>
<asp:PlaceHolderrunat="server"ID="phMainContent" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content
[Default.aspx.cs]
protected void btnLoadPage1_Click(object sender, EventArgs e)
{
Control ctrlDynamicPage = LoadControl("~/WebUserControls/Page1.acx");
phMainContent.Controls.Add(ctrlDynamicPage);
}

Again, I haven't tested this code but this was what I had in mind. In order to add more pages you just need to create them in web user controls and then make sure you have a DB or something with the virtual path the loader needs to fetch.

Best regards,
DBA


Hi DBA,

I see what you suggest. I don't know if this is the solution for Rayak. The solution you suggest stays on the same page and reloads it with usercontrols. This can be a solution. if its possible to create a trigger from a control of the masterpage.

Regards,


Dennis van de Laar:

Hi DBA,

I see what you suggest. I don't know if this is the solution for Rayak. The solution you suggest stays on the same page and reloads it with usercontrols. This can be a solution. if its possible to create a trigger from a control of the masterpage.

Regards,

You don't have to do that. You just need to have something like this in your web user control:

<asp:Button runat="server" ID="btnMyAction" OnClick="DoSomething" /><asp:UpdatePanel UpdateMode="Conditional"><Triggers><asp:AsyncPostBackTrigger ControlId="btnMyAction" EventName="Click" /></Triggers><ContentTemplate><asp:Label runat="server" ID="lblTest" Text="not updated" /></ContentTemplate></asp:UpdatePanel>
In the code behind of the web user control:
protected void DoSomething(object sender, EventArgs e){ lblTest.Text ="updated by ajax callback";}
With this you are encapsulating the update panels, which again is not the optimal solution if you are considering resources. But, the bottom line is that it should work and solve the presented problem.
Best regards.


If RayaK just wants to prevent the static content flickering when navigating between screens:

- if your content is really "static" (the position, height etc. are the same for each page) you won't get flicker on firefox (not 100%, sometimes even firefox flickers)

- ie6 and (saddly) ie7 usually will flicker, but you can eliminate this flicker with the following in the codebehind (put it in the oninit or onload). (Firefox simply ignores this.)

HtmlMeta meta = new HtmlMeta( );
meta.Attributes.Add( "http-equiv", "Page-Enter" );
meta.Attributes.Add( "content", "progid:DXImageTransform.Microsoft.Fade(duration=0)" );
this.Header.Controls.AddAt( 0, meta );

This trick and forms are well "documented" all over the web.

No comments:

Post a Comment