p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

Free Code from Wrox
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other programmers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 15th, 2009, 12:18 AM
Authorized User
Points: 48, Level: 1
Points: 48, Level: 1 Points: 48, Level: 1 Points: 48, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2007
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sully7
Default Updating Page Title when SelectedIndexChanged

Hi all,

I'm trying to make it so that the title of my page updates when the selected choice from either the BrowseProducts or BrowseArticles page changes, and I'm having a lot of trouble figuring this out. The ddlDepartments_SelectedIndexChanged only binds data with gvw.Products.DataBind(); however I'm trying to edit the code for BrowseProducts.aspx.cs to update the title in the following way:

Code:
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;
using MB.TestingMachines;
using MB.TestingMachines.BLL.Store;

namespace MB.TestingMachines.UI
{
   public partial class BrowseProducts : BasePage
   {
      int _departmentID = 0;
       protected void Page_Load(object sender, EventArgs e)
      {
         if (!string.IsNullOrEmpty(this.Request.QueryString["DepID"]))
          _departmentID = int.Parse(this.Request.QueryString["DepID"]);

         if (!this.IsPostBack)
         {
             // try to load the product with the specified ID, and raise an exception if it doesn't exist
             Department department = Department.GetDepartmentByID(_departmentID);
             if (department == null)
                 this.Title = String.Format(this.Title, ("All Products"));
             else
                 this.Title = String.Format(this.Title, (department.Title));
         }
      <!-- THIS IS WHERE I'D ASSUME SOME CODE WOULD GO? -->
      }
   }
}
And the code for the ASPX page is:
Code:
<%@ Page Language="C#" MasterPageFile="~/page.master" EnableEventValidation="false" AutoEventWireup="true" CodeFile="BrowseProducts.aspx.cs" Inherits="MB.TestingMachines.UI.BrowseProducts" Title="Lako Tool | {0}" %>
<%@ MasterType VirtualPath="~/page.master" %>
<%@ Register Src="./Controls/ProductListing.ascx" TagName="ProductListing" TagPrefix="mb" %>

<asp:Content ID="Content" ContentPlaceHolderID="pagecol1" Runat="Server">
<p class="header">Product Catalog</p>
<div class="colText">

   <mb:ProductListing id="ProductListing1" runat="server" />
   
</div>
</asp:Content>
I've tried a few things so far, but nothing has worked. Any tips?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old November 15th, 2009, 12:20 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,544, Level: 28
Points: 4,544, Level: 28 Points: 4,544, Level: 28 Points: 4,544, Level: 28
Activity: 48%
Activity: 48% Activity: 48% Activity: 48%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 859
Thanks: 12
Thanked 150 Times in 149 Posts
Default

Since you already have the department names in the ddlDepartments drop down list, probably the easiest way to do this would be to snag it from there in the ddlDepartments_SelectedIndexChanged event handler in ProductListing.ascx.cs.

Code:
protected void ddlDepartments_SelectedIndexChanged(object sender, EventArgs e)
{
   this.Page.Title += " - " + ddlDepartments.SelectedItem.Text;
   
   gvwProducts.PageIndex = 0;
   gvwProducts.DataBind();
}
__________________
Author of the upcoming ASP.NET 4.0 Website Programming: Problem - Design - Solution

Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old November 15th, 2009, 12:51 PM
Authorized User
Points: 48, Level: 1
Points: 48, Level: 1 Points: 48, Level: 1 Points: 48, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2007
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sully7
Default

Lee,

Thanks! This definitely worked!
For anyone that wants to know for future reference, this is the overall final code that worked for me:

BrowseProducts.aspx.cs
Code:
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;
using MB.TestingMachines;
using MB.TestingMachines.BLL.Store;

namespace MB.TestingMachines.UI
{
   public partial class BrowseProducts : BasePage
   {
      int _departmentID = 0;

       protected void Page_Load(object sender, EventArgs e)
      {
         if (!string.IsNullOrEmpty(this.Request.QueryString["DepID"]))
          _departmentID = int.Parse(this.Request.QueryString["DepID"]);

         if (!this.IsPostBack)
         {
             // try to load the product with the specified ID, and raise an exception if it doesn't exist
             Department department = Department.GetDepartmentByID(_departmentID);
             if (department == null)
                 this.Page.Title += "All Products";
             else
                 this.Page.Title += department.Title;
         }
      }
   }
}

BrowseProducts.aspx
Code:
<%@ Page Language="C#" MasterPageFile="~/page.master" EnableEventValidation="false" AutoEventWireup="true" CodeFile="BrowseProducts.aspx.cs" Inherits="MB.TestingMachines.UI.BrowseProducts" Title="Lako Tool |  " %>
<%@ MasterType VirtualPath="~/page.master" %>
<%@ Register Src="./Controls/ProductListing.ascx" TagName="ProductListing" TagPrefix="mb" %>

<asp:Content ID="Content" ContentPlaceHolderID="pagecol1" Runat="Server">
<p class="header">Product Catalog</p>
<div class="colText">

   <mb:ProductListing id="ProductListing1" runat="server" />
   
</div>
</asp:Content>
ProductListing.ascx.cs (for ddlDepartments_SelectedIndexChanged)
Code:
       
protected void ddlDepartments_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Page.Title += ddlDepartments.SelectedItem.Text;

            gvwProducts.PageIndex = 0;
            gvwProducts.DataBind();
        }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old November 15th, 2009, 01:46 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,544, Level: 28
Points: 4,544, Level: 28 Points: 4,544, Level: 28 Points: 4,544, Level: 28
Activity: 48%
Activity: 48% Activity: 48% Activity: 48%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 859
Thanks: 12
Thanked 150 Times in 149 Posts
Default

You're welcome.
__________________
Author of the upcoming ASP.NET 4.0 Website Programming: Problem - Design - Solution

Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to print a web page without title, URL, page #, date and time Mattt C# 2 July 17th, 2009 04:02 AM
Page links in forum title jimibt BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 October 17th, 2007 05:37 PM
SelectedIndexChanged wont fire in content page alemadlei ASP.NET 2.0 Basics 1 May 28th, 2006 12:00 PM
Changing Page Title From User Control hugh@kmcnetwork.com ASP.NET 1.0 and 1.1 Professional 5 October 11th, 2005 09:48 AM
Animated scrolling page title joshil Flash (all versions) 1 May 14th, 2004 04:45 PM



All times are GMT -4. The time now is 11:15 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© 2010 Wiley Publishing, Inc