|
|
 |
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 .
|
|
 |

November 15th, 2009, 12:18 AM
|
|
Authorized User
|
|
Join Date: Sep 2007
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|

November 15th, 2009, 12:20 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 859
Thanks: 12
Thanked 150 Times in 149 Posts
|
|
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();
}
|

November 15th, 2009, 12:51 PM
|
|
Authorized User
|
|
Join Date: Sep 2007
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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();
}
|

November 15th, 2009, 01:46 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 859
Thanks: 12
Thanked 150 Times in 149 Posts
|
|
You're welcome.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |