Prev: Getting error when trying to upload large files on ftp location
Next: SqlDataSource Control vs Connecting to a Database Programmatically
From: Tom Becker on 3 May 2010 08:45 Hallo I'm trying to access some public functions of a master page from a content page. Casting a base masterpage to a specific one (that contains my functions) results in a runtime error: protected void Page_Load(object sender, EventArgs e) { MyNameSpace.MasterPages.Main temp = Master as MyNameSpace.MasterPages.Main; Debug.Assert(temp != null, "Error casting"); temp.DoSomething(); ... } I googled the error and it seems that the same issue occurs more than once. There is also a bugfix from Microsoft "NDP20-KB915782-X86.exe" but I can't install it. Using <%@ MasterType VirtualPath="~/MasterPages/Main.Master"%> doesn't solve the problem either as the compiler just overwrites the Master-property. BTW I'm using Visual Studio 2008 sp1 and .net3.5 SP1 Any suggestions? Tom
From: Alexey Smirnov on 3 May 2010 17:07
On May 3, 2:45 pm, Tom Becker <tdotbeckeratapedotde> wrote: > Hallo > > I'm trying to access some public functions of a master page from a > content page. > > Casting a base masterpage to a specific one (that contains my functions) > results in a runtime error: > > protected void Page_Load(object sender, EventArgs e) > { > MyNameSpace.MasterPages.Main temp = Master as > MyNameSpace.MasterPages.Main; > > Debug.Assert(temp != null, "Error casting"); > > temp.DoSomething(); > > ... > > } > > I googled the error and it seems that the same issue occurs more than > once. There is also a bugfix from Microsoft "NDP20-KB915782-X86.exe" > but I can't install it. > > Using > <%@ MasterType VirtualPath="~/MasterPages/Main.Master"%> > doesn't solve the problem either as the compiler just overwrites > the Master-property. > > BTW I'm using Visual Studio 2008 sp1 and .net3.5 SP1 > > Any suggestions? > Tom Well, I think your code looks correct. If I were you I would try to make a simple test with new master and content page to see if you can reproduce the issue. Maybe it's a kind of naming problem or something like this. |