Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 15th, 2009, 12:18 AM
Authorized User
 
Join Date: Sep 2007
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?
 
Old November 15th, 2009, 12:20 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 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();
}
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old November 15th, 2009, 12:51 PM
Authorized User
 
Join Date: Sep 2007
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();
        }
 
Old November 15th, 2009, 01:46 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

You're welcome.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}





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 03: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 04:37 PM
SelectedIndexChanged wont fire in content page alemadlei ASP.NET 2.0 Basics 1 May 28th, 2006 11:00 AM
Changing Page Title From User Control [email protected] ASP.NET 1.0 and 1.1 Professional 5 October 11th, 2005 08:48 AM
Animated scrolling page title joshil Flash (all versions) 1 May 14th, 2004 03:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.