 |
BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8  | This is the forum to discuss the Wrox book Beginning ASP.NET 2.0 by Chris Hart, John Kauffman, David Sussman, Chris Ullman; ISBN: 9780764588501 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 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
|
|
|
|
|

January 19th, 2009, 08:29 AM
|
|
Authorized User
|
|
Join Date: Dec 2008
Posts: 56
Thanks: 1
Thanked 1 Time in 1 Post
|
|
Problem with try it out Chapter 11 p 408
hi there,
On this example, when a value is picked from the drop down menu then must bring automatically the proper theme. But it does not. Tried the done example and has the same problem. Here is the classâs code.
using System;
using System.Web;
using System.Web.UI;
namespace Osfp.Web.GlobalEvents
{
public class bgclass : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(this.app_PreRequestHandlerExecute);
}
private void app_PreRequestHandlerExecute(object Sender, EventArgs E)
{
Page p = HttpContext.Current.Handler as Page;
if (p != null)
{
ProfileCommon pb = (ProfileCommon)HttpContext.Current.Profile;
p.Theme = pb.Theme;
}
}
public void Dispose()
{
}
}
}
|
|

January 19th, 2009, 12:45 PM
|
|
Authorized User
|
|
Join Date: Dec 2008
Posts: 56
Thanks: 1
Thanked 1 Time in 1 Post
|
|
anyone ?
|
|

January 20th, 2009, 03:45 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
What exactly is the problem. Do you get an error? If so, which one?
Also, you probably need to configure the handler in the webconfig. Have you done that?
Finally, what happens when you set a breakpoint on the line that starts with "Page p" and then debug your site. Does the breakpoint get hit?
Imar
|
|

January 20th, 2009, 11:57 AM
|
|
Authorized User
|
|
Join Date: Dec 2008
Posts: 56
Thanks: 1
Thanked 1 Time in 1 Post
|
|
what i want to do is, when i pick a value from the drop down menu, to automatically change the background. this happens, but only when i change a web page. i tried to add autopostback=true in the drop down menu but did not change anything.
hope this helps
|
|

January 20th, 2009, 11:59 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Can you answe the other questions? Otherwise it's difficult to suggest something useful...
Imar
|
|

January 20th, 2009, 12:09 PM
|
|
Authorized User
|
|
Join Date: Dec 2008
Posts: 56
Thanks: 1
Thanked 1 Time in 1 Post
|
|
Well i do not get any erros.
i have configured the handler in the webconfig.
When i add the break point to the place you told me and run it, the goes throung the if statment and loads the theme
In my case, what i am trying to do is when i pick a value from the drop down menu to load it automatically without loading other page to view the different theme.
|
|

January 20th, 2009, 12:13 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I think I know what the problem is...
Themes are applied pretty early in the page's life cycle. So, when you set the theme after a postback, the current theme is already loaded, and the new theme settings are not applied.
The usual way around this is to redirect after them has been applied. Something like:
Response.Redirect(Request.Url.ToString();
should do the trick....
Imar
|
|

January 20th, 2009, 12:15 PM
|
|
Authorized User
|
|
Join Date: Dec 2008
Posts: 56
Thanks: 1
Thanked 1 Time in 1 Post
|
|
so but i am well amature, could you please tell me where to past this code?
thank you!
|
|

January 20th, 2009, 12:19 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Directly after the line that sets the profile. You may not have direct access to the Response and Request objects. If that's the case, you need to use HttpContext.Current. like this:
p.Theme = pb.Theme;
HttpContext myContext = HttpContext.Current;
myContext.Response.Redirect(myContext.Request.Url. ToString());
Hope this helps,
Imar
|
|

January 20th, 2009, 12:25 PM
|
|
Authorized User
|
|
Join Date: Dec 2008
Posts: 56
Thanks: 1
Thanked 1 Time in 1 Post
|
|
unfortunately an Error appeard
'System.Web.HttpContext' does not contain a definition for 'myContext'
i also tried the first option you told me with the same result!
|
|
 |