Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional 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 March 23rd, 2007, 02:19 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to tell a User Control Who its Daddy is

I'm building a Content Management System that allows the user to dynamically change the MasterPageFile property of a page. I have 4 MasterPages setup that look different, but have all the same code on them. Each of them inherits from a base class I defined called BaseMasterPage. I got this from an excellent article on the subject located at http://odetocode.com/Articles/450.aspx.

Each MasterPage has this one user control on it. I handle the events of the control in the MasterPage, using the RaiseBubbleEvent method inside the user control.

The problem is that the user control is bubbling its events to the MasterPage declared in the @Page directive, not the one we dynamically changed to during the page's PreInit event. Then events on the User Control bring back controls that weren't originally in the ViewState. Since I'm using an UpdatePanel, I get the "Cannot Load ViewState" error.

How can I tell the control which MasterPage to bubble its events to?

Thanks.

 
Old March 23rd, 2007, 04:25 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nevermind, I figured this out.

The problem was that in the page's preInit ...

Code:
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
     If IsPostBack = False Then     'this was the mistake
          Me.MasterPageFile = "~/MasterPages/Level" & dr("intMaster").ToString & "Master.Master"
     End If
End Sub
By only doing this when isPostback was false, I was basically insuring that any event that triggered an asynchronous postback would bring back different ViewState data with it. Stupid mistake. Oh Well.

Aaron






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to tell a User Control Who its Daddy is Aaron Edwards ASP.NET 2.0 Basics 1 March 23rd, 2007 04:25 PM
VWD 2005 Expr - Go Daddy SQL Server problem dmitcha Visual Studio 2005 2 January 2nd, 2007 09:32 AM
MS Access/Go Daddy Connections jroxit Classic ASP Basics 1 September 18th, 2006 12:32 PM
Add Windows User control in Web User Control agarwalvidhu C# 0 March 30th, 2006 01:17 AM
Help! Custom Server Control using User Control diehard ASP.NET 1.0 and 1.1 Professional 2 January 4th, 2006 12:33 PM





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