Connecting Tech Pros Worldwide Forums | Help | Site Map

Calling procedure in Masterpage from User Control

Christiano Donke
Guest
 
Posts: n/a
#1: Nov 21 '08
Hello...

I have this UserControl (login.ascx -Login), that is placed in a
Masterpage (Layout.master -Layout).

How can I call a sub (RedrawMenu) that is place in the code-behind of the
master page from within a sub inside the UserControl???



i'm having all this issues because all the components are inseide
UpdatePanels, to avoid the whole page reload.. but know, the function is not
being called...

Searching the web, i've found something like this:
Dim cmp As CustomMasterPage = CType(Master, CustomMasterPage)

But since i'm in an User Control, it doesn't work...


tks in advance...
Christiano



Christiano Donke
Guest
 
Posts: n/a
#2: Nov 21 '08

re: Calling procedure in Masterpage from User Control


ok...so I should replace the MasterPage1 by my Masterpage name, right???

so it will be:
Layout m = this.Page.Master as Layout;
m.RedrawMenu();

since i'm using VB:
Dim m as Layout = TryCast(Me.Page.Master, Layout)
m.RedrawMenu

But VS is complainig that "Layout is not defined"

should i have it declared somewhere before?


tks..


"Jérémy Jeanson" <jeremy.jeanson@free.frescreveu na mensagem
news:uGud3i%23SJHA.3880@TK2MSFTNGP04.phx.gbl...
Quote:
To do, you have to write RedrawMenu as public methode and in the
UserControl you have to user the Master property of the Page
>
Exemeple:
>
// in you master (MasterPage1)code-behind:
>
public void RedrawMenu()
{
>
}
>
// In the UserControl :
>
MasterPage1 m = this.Page.Master as MasterPage1;
m.RedrawMenu();
>
--
Jérémy JEANSON
MCP
http://jeremy.blogdns.net

=?Utf-8?B?YnJ1Y2UgYmFya2Vy?=
Guest
 
Posts: n/a
#3: Nov 21 '08

re: Calling procedure in Masterpage from User Control


while this is a giood design practice, the simple solution is to use the
@MasterType directive which will type the Master page property for you, so no
casts are required.

-- bruce (sqlwork.com)


"Jérémy Jeanson" wrote:
Quote:
Damn...
>
You have this isue because your project is a website, not an application.
>
To solve this, you have 2 ways:
1) use a web application
>
2) create an interface that will be use by your masterpage
>
Public Interface ILayout
Sub RedrawMenu()
End Interface
>
Partial Public Class Layout
Inherits System.Web.UI.MasterPage
Implements ILayout
>
Public Sub RedrawMenu() Implements ILayout.RedrawMenu
>
End Sub
End Class
>
Partial Class WebUserControl
Inherits System.Web.UI.UserControl
>
Public Sub New()
Dim m As ILayout = TryCast(Me.Page.Master, ILayout)
m.RedrawMenu()
End Sub
End Class
>
--
Jérémy JEANSON
MCP
http://jeremy.blogdns.net
>
Christiano Donke
Guest
 
Posts: n/a
#4: Nov 21 '08

re: Calling procedure in Masterpage from User Control


Is it bad to be a Web Site and not a WebApplication???

I've tried converting it to an application... But.. Can I still use ajax?
and other components???

I figured out already that the Web.Config has been replaced by the
Settings.vb file..
What about the Authentication/Authorization statements???


I usually use Web Site projects and not the Web

(Both lame questions, but I need to ask it... lol)



"Jérémy Jeanson" <jeremy.jeanson@free.frescreveu na mensagem
news:%23D4e96%23SJHA.5344@TK2MSFTNGP06.phx.gbl...
Quote:
Damn...
>
You have this isue because your project is a website, not an application.
>
To solve this, you have 2 ways:
1) use a web application
>
2) create an interface that will be use by your masterpage
>
Public Interface ILayout
Sub RedrawMenu()
End Interface
>
Partial Public Class Layout
Inherits System.Web.UI.MasterPage
Implements ILayout
>
Public Sub RedrawMenu() Implements ILayout.RedrawMenu
>
End Sub
End Class
>
Partial Class WebUserControl
Inherits System.Web.UI.UserControl
>
Public Sub New()
Dim m As ILayout = TryCast(Me.Page.Master, ILayout)
m.RedrawMenu()
End Sub
End Class
>
--
Jérémy JEANSON
MCP
http://jeremy.blogdns.net

Mark Rae [MVP]
Guest
 
Posts: n/a
#5: Nov 21 '08

re: Calling procedure in Masterpage from User Control


"Christiano Donke" <cdonke@digiexpress.com.brwrote in message
news:epH1nLATJHA.5344@TK2MSFTNGP06.phx.gbl...
Quote:
Quote:
>You have this isue because your project is a website, not an application.
>>
>To solve this, you have 2 ways:
>1) use a web application
>
Is it bad to be a Web Site and not a WebApplication???
Matter of opinion - I never use the website model...
Quote:
I've tried converting it to an application... But.. Can I still use ajax?
and other components???
Yes.
Quote:
I figured out already that the Web.Config has been replaced by the
Settings.vb file..
Ah - sounds like you've converted your website to a WinForms application,
not a web application...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Closed Thread