How to switch content page?

B

Ben

Hi,

i'm trying to build a simple site navigation (using c#)... i
implemented a master page that shows a sidebar user control on the
left side, and a content page on the right.

i click the link on the sidebar which calls Redirect.

problem is that the whole page refreshes... i just want the right side
to update to a new content.

can anyone point me in the right direction to accomplish this?

btw, i'm trying to use ajax when possible to make the job easier...
but if i put the sidebar in an UpdatePanel (in hopes of avoiding a
refresh) it gives this error:

"Sys.WebForms.PageRequestManagerParserErrorException: The message
received from the server could not be parsed. Common causes for this
error are when the response is modified by calls to Response.Write()"


Thanks for any info you can give!
 
G

Guest

Hi,

i'm trying to build a simple site navigation (using c#)... i
implemented a master page that shows a sidebar user control on the
left side, and a content page on the right.

i click the link on the sidebar which calls Redirect.

problem is that the whole page refreshes... i just want the right side
to update to a new content.

can anyone point me in the right direction to accomplish this?

btw, i'm trying to use ajax when possible to make the job easier...
but if i put the sidebar in an UpdatePanel (in hopes of avoiding a
refresh) it gives this error:

"Sys.WebForms.PageRequestManagerParserErrorException: The message
received from the server could not be parsed. Common causes for this
error are when the response is modified by calls to Response.Write()"

Thanks for any info you can give!

http://alpascual.com/blog/al/archiv...questManagerParserErrorException-in-AJAX.aspx
 
B

Ben


Thanks for the quick response, that solved that error, however the
entire page still refreshes....

how do i make it so just the content page (right side) changes to a
different web form? if i need to drop master pages i can... just
trying to create a clean design, where i have a seperate web form for
each page, and the side bar on the left does not refresh.
 
M

Mark Rae [MVP]

Thanks for the quick response, that solved that error, however the
entire page still refreshes....

how do i make it so just the content page (right side) changes to a
different web form? if i need to drop master pages i can... just
trying to create a clean design, where i have a seperate web form for
each page, and the side bar on the left does not refresh.

Sounds like you're making the "classic" mistake with MasterPages by thinking
that they are somehow the ASP.NET version of framesets....

MasterPages are nothing at all like framesets... In fact, a MasterPage isn't
a page at all - it's little more than a UserControl. If Microsoft had called
them LayoutControls instead of MasterPages, this confusion would never have
occurred...

When a content page is requested, it loads its MasterPage(s) and merges the
markup to form a single HTML page which is streamed down to the client, just
like any other ASP.NET page...

If you don't want this to happen, then you will need to go back to old
framesets or, maybe, use an <iframe>.

However, I strongly advise you not to even consider this, and to stick with
MasterPages...
 
B

Ben

Sounds like you're making the "classic" mistake with MasterPages by thinking
that they are somehow the ASP.NET version of framesets....

MasterPages are nothing at all like framesets... In fact, a MasterPage isn't
a page at all - it's little more than a UserControl. If Microsoft had called
them LayoutControls instead of MasterPages, this confusion would never have
occurred...

When a content page is requested, it loads its MasterPage(s) and merges the
markup to form a single HTML page which is streamed down to the client, just
like any other ASP.NET page...

If you don't want this to happen, then you will need to go back to old
framesets or, maybe, use an <iframe>.

However, I strongly advise you not to even consider this, and to stick with
MasterPages...

Thanks Mark -- That's why I looked into master pages, since i read
that framesets are a thing of the past...

but isn't there some solution to just re-load the right side (the
content) and leave the left (the menu sidebar) in-tact? It doesn't
look professional when the whole page refreshes every time someone
clicks a new menu item.... or is the only way to accomplish this
using framesets?!?
 
M

Mark Rae [MVP]

Thanks Mark -- That's why I looked into master pages, since i read
that framesets are a thing of the past...

but isn't there some solution to just re-load the right side (the
content) and leave the left (the menu sidebar) intact?

Not with MasterPages...
It doesn't look professional when the whole page refreshes every time
someone clicks a new menu item....

That's the way the web works...
or is the only way to accomplish this using framesets?!?

One of the main features of MasterPages is the server-side interoperability
between the content pages and MasterPages - you can't really do this with
framesets or iframes, so you're left with client-side JavaScript.

Obviously, you could create an asp:Literal control and fill it dynamically
with HTML, but that would mean that you would lose all of the server-side
ASP.NET functionality.

I would strongly advise you to stick with MasterPages - once you've got the
hang of them, you'll wonder how you ever managed without them...
 
B

Ben

Not with MasterPages...


That's the way the web works...


One of the main features of MasterPages is the server-side interoperability
between the content pages and MasterPages - you can't really do this with
framesets or iframes, so you're left with client-side JavaScript.

Obviously, you could create an asp:Literal control and fill it dynamically
with HTML, but that would mean that you would lose all of the server-side
ASP.NET functionality.

I would strongly advise you to stick with MasterPages - once you've got the
hang of them, you'll wonder how you ever managed without them...

yea, i want to avoid dynamically filling the HTML on the client
side... i was really hoping for the exact same functionality framesets
provided (being able to reload a particular frame), i just thought
there's an alternative that would behave in a similar way.

u know that MSDN page for the subscriber downloads... it's got a
navigation tree on the left, and it doesn't refresh when you click
things, just the content pane refreshes... that's what i wanted...
maybe they're using framesets...

btw, if there's any recommended book u can suggest that covers these
topics (i'm using VS 2008 now), let me know, i'd really appreciate
it... i think i need to get some basics down.

thanks!!
 
M

Mark Rae [MVP]

You know that MSDN page for the subscriber downloads... it's got a
navigation tree on the left, and it doesn't refresh when you click
things, just the content pane refreshes... that's what I wanted...
maybe they're using framesets...

The "content" pages are static HTML stored in a database...

BTW, if there's any recommended book you can suggest that covers these
topics (I'm using VS 2008 now), let me know, I'd really appreciate
it... I think I need to get some basics down.

http://www.kencox.ca/
 
R

Regan

It might be easier for you to consider building your side menus into your
content pages instead of the master page. Then you could definitely do
partial page updates using nested update panels.

Regan
 
M

Mark Rae [MVP]

It might be easier for you to consider building your side menus into your
content pages instead of the master page. Then you could definitely do
partial page updates using nested update panels.

Apart from the fact that that would totally defeat the purpose of
MasterPages...
 
B

Ben

Apart from the fact that that would totally defeat the purpose of
MasterPages...

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net- Hide quoted text -

- Show quoted text -

This is closer to what i need though... i'd rather not use a master
page in this section if it forces a full refresh.

I''m testing it now... so built a table with 2 columns in a webform,
one side has my menu and the other an UpdatePanel.
On menu item click I load a new Web User Control into the UpdatePanel
using this code:

UpdatePanel.ContentTemplateContainer.Controls.Clear();
UserControl uc =
(UserControl)LoadControl(sPathToWebUI);
UpdatePanel.ContentTemplateContainer.Controls.Add(uc);

It has a strange behavior -- when the contol loads, I click on a
button and it doesn't post back... i click again and only then it
works... is there anyway to fix this?
 
R

Regan

I tried recreating your columns and update panel just to test it. I added a
"parent" update panel that holds everything except the Script Manager. And
then I dropped a variation of your code into my button onClick, which
created a Textbox control in the right column's Update Panel.

As expected, the partial post back worked fine. (with the "parent" Update
Panel). I would suggest, breaking through your user control; the two-click
bug might be in there.



I'm not sure what the code for your control looks like.
 
B

Ben

I tried recreating your columns and update panel just to test it. I added a
"parent" update panel that holds everything except the Script Manager.  And
then I dropped a variation of your code into my button onClick, which
created a Textbox control in the right column's Update Panel.

As expected, the partial post back worked fine. (with the "parent" Update
Panel). I would suggest, breaking through your user control; the two-click
bug might be in there.

I'm not sure what the code for your control looks like.










- Show quoted text -

Thanks for trying it !! ...i still can't figure out what's wrong. The
left side holds a menu with 3 items. 2 of them point to almost empty
user controls (with just a text heading), the other points to a user
control with a heading, a button and a textbox... the onclick of the
button has code to simply put the current date in the textbox. If I
click on that menu item first, it switches to that page and I can
click the button and it posts right away and displays the time... but
if i switch to another menu item and then come back to the one with
the textbox, it takes 2 clicks to get it to post correctly (when
debugging i can see it goes to the main form's Page_Onload and then to
the User Control's Page_Onload, but does not proceed to the
Button1_Click of the user control). Here's the code, maybe someone
sees the problem?


Main form table:
----------------------------

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Table ID="Table1" runat="server" Width="100%">
<asp:TableRow ID="TableRow1" runat="server">
<asp:TableCell ID="TableCell1" runat="server"
ColumnSpan="2"><center>
<asp:Label ID="Label1" runat="server" Text="Label"
CssClass="PageHeader">SIMS Admin Console</asp:Label></center></
asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRow2" runat="server">
<asp:TableCell ID="TableCell2" runat="server" Width="20%">

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

<ContentTemplate>
<asp:Menu ID="Menu1" runat="server"
OnMenuItemClick="Menu1_MenuItemClick" >
<Items>

<asp:MenuItem Text="Load
Control1"></asp:MenuItem>
<asp:MenuItem Text="Load
Control2"></asp:MenuItem>
<asp:MenuItem Text="Load
Control3"></asp:MenuItem>

</Items>
</asp:Menu>

</ContentTemplate>
</asp:UpdatePanel>


</asp:TableCell>


<asp:TableCell ID="TableCell3" runat="server">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>

</ContentTemplate>
</asp:UpdatePanel>
</asp:TableCell>
</asp:TableRow>
</asp:Table>


Main Form Code:
------------------------------

private const string BASE_PATH = "~/";



protected void Page_Load(object sender, EventArgs e)
{
LoadUserControl();

}

protected void Menu1_MenuItemClick(object sender,
MenuEventArgs e)
{
MenuItem menu = e.Item;

string controlPath = string.Empty;

switch (menu.Text)
{
case "Load Control2":
controlPath = BASE_PATH +
"WebUIClientSummary.ascx";
break;
case "Load Control3":
controlPath = BASE_PATH +
"WebUIConfigSummary.ascx";
break;
default:
controlPath = BASE_PATH + "WebUIMainSummary.ascx";
break;
}

LastLoadedControl = controlPath;
LoadUserControl();
}


private string LastLoadedControl
{
get
{
return ViewState["LastLoaded"] as string;
}
set
{
ViewState["LastLoaded"] = value;
}



}

private void LoadUserControl()
{
string controlPath = LastLoadedControl;


if (!string.IsNullOrEmpty(controlPath))
{

UpdatePanel2.ContentTemplateContainer.Controls.Clear();
UserControl uc =
(UserControl)LoadControl(controlPath);

UpdatePanel2.ContentTemplateContainer.Controls.Add(uc);
}
}


User Control Source:
---------------------------------

<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="WebUIClientSummary.ascx.cs"
Inherits="WebApplication1.WebUIClientSummary" %>
<p>
Client Summary</p>
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


User Control Code:
-------------------------------

namespace WebApplication1
{
public partial class WebUIClientSummary :
System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = DateTime.Now.ToString();
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,250
Latest member
Charlesreero

Latest Threads

Top