Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

How to switch content page?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ben - 09 Mar 2008 11:26 GMT
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!
Alexey Smirnov - 09 Mar 2008 11:37 GMT
> Hi,
>
[quoted text clipped - 18 lines]
>
> Thanks for any info you can give!

http://alpascual.com/blog/al/archive/2007/04/26/How-to-fix-Sys.WebForms.PageRequ
estManagerParserErrorException-in-AJAX.aspx

Ben - 09 Mar 2008 11:49 GMT
> > Hi,
>
[quoted text clipped - 22 lines]
>
> - Show quoted text -

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.
Mark Rae [MVP] - 09 Mar 2008 12:56 GMT
>> http://alpascual.com/blog/al/archive/2007/04/26/How-to-fix-Sys.WebFor...-
>> Hide quoted text -
[quoted text clipped - 8 lines]
> 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...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Ben - 09 Mar 2008 14:35 GMT
> >>http://alpascual.com/blog/al/archive/2007/04/26/How-to-fix-Sys.WebFor...
> >> Hide quoted text -
[quoted text clipped - 30 lines]
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net

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?!?
Mark Rae [MVP] - 09 Mar 2008 15:22 GMT
> 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...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Ben - 09 Mar 2008 15:57 GMT
> > Thanks Mark -- That's why I looked into master pages, since i read
> > that framesets are a thing of the past...
[quoted text clipped - 25 lines]
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net

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!!
Mark Rae [MVP] - 09 Mar 2008 16:10 GMT
> 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/

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Regan - 09 Mar 2008 17:48 GMT
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

>> 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
[quoted text clipped - 8 lines]
>
> http://www.kencox.ca/
Mark Rae [MVP] - 09 Mar 2008 18:19 GMT
>>> 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
[quoted text clipped - 12 lines]
> 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...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Ben - 09 Mar 2008 19:26 GMT
> >>> 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
[quoted text clipped - 21 lines]
>
> - 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?
Regan - 09 Mar 2008 22:13 GMT
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.

>> >>> 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
[quoted text clipped - 39 lines]
> button and it doesn't post back... i click again and only then it
> works... is there anyway to fix this?
Ben - 10 Mar 2008 02:30 GMT
> 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
[quoted text clipped - 56 lines]
>
> - 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();
       }
   }
}

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.