Public Class MyMaster
Inherits BaseMasterPage
Public Sub ShowModal(showHide As String)
If showHide = "Show" Then
mpuEmail.Show()
ElseIf showHide = "Hide" Then
mpuEmail.Hide()
End If
End Sub
And in temp.aspx.vb i have the following sub
Public Sub ShowModal(showhide As String)
Dim masterPage As MyMaster = TryCast(Page.Master, MyMaster)
masterPage.ShowModal(showhide)
End Sub
Finally on a button click also in temp.aspx.vb, I have the following code
Protected Sub Button1_Click(sender As Object, e As EventArgs)
ShowModal("Hide")
End Sub
I get an object not set to an instance error on the masterPage.ShowModal(showhide) line.
I have debugged it and its not the master. Ive changed it slightly so that the button click calls a Public Sub in the Masterpage. I can get to the sub but the sub cant find the modal? I'm pretty sure its all a problem with finding the modal.
Public sub in basemasterpage code behind (I get a object set to nothing.. error on mpuEmail.show()) Everything else stacks up? So i'm sure this sub cant find the modal. I've tried to use findcontrol but that doesnt find it. Intellisense can find it ok?
Public Sub ShowModal(showHide As String)
If showHide = "Show" Then
mpuEmail.Show()
ElseIf showHide = "Hide" Then
mpuEmail.Hide()
End If
End Sub
Code on button click in aspx code behind
Dim master1 = TryCast(Me.Master, BaseMasterPage)
If master1 IsNot Nothing Then
master1.ShowModal("Show")
End If
Any further ideas - ive been trying to get this to popup for days. If i move the the modal out of the contentplaceholder it wont hide. Is it becasue the modal is in the contentplaceholder?
leonaisse
Member
40 Points
77 Posts
Using class in masterpage
Nov 27, 2012 01:14 PM|LINK
Hi
I have a master page called basemasterpage which has a modalpopextender called mpuEmail
<asp:ContentPlaceHolder ID="mainContent" runat="server"> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Panel ID="emailPanel" runat="server"> <uc:emailPopup ID="ucemailPopup" runat="server" /> </asp:Panel> </ContentTemplate> </asp:UpdatePanel> <cc1:ModalPopupExtender ID="mpuEmail" runat="server" PopupControlID="emailPanel" TargetControlID="btnHdn"></cc1:ModalPopupExtender> <asp:Button ID="btnHdn" runat="server" Text="Button" Visible="false" /> </asp:ContentPlaceHolder>basemasterpage has a class in its code behind
Public Class MyMaster Inherits BaseMasterPage Public Sub ShowModal(showHide As String) If showHide = "Show" Then mpuEmail.Show() ElseIf showHide = "Hide" Then mpuEmail.Hide() End If End SubAnd in temp.aspx.vb i have the following sub
Public Sub ShowModal(showhide As String) Dim masterPage As MyMaster = TryCast(Page.Master, MyMaster) masterPage.ShowModal(showhide) End SubFinally on a button click also in temp.aspx.vb, I have the following code
Protected Sub Button1_Click(sender As Object, e As EventArgs) ShowModal("Hide") End SubI get an object not set to an instance error on the masterPage.ShowModal(showhide) line.
Any ideas?
Thank you so much i've been on this for hours.
Leonaisse
chetan.sarod...
All-Star
65839 Points
11163 Posts
Re: Using class in masterpage
Nov 28, 2012 02:18 AM|LINK
If youa re getting an error " object not set to an instance" at masterPage.ShowModal(showhide) line, means masterPage object is null
Try to debug your code, set breakpoint @ Dim masterPage As MyMaster = TryCast(Page.Master, MyMaster), see if masterPage object is not null
http://forums.asp.net/t/1850042.aspx/1
http://forums.asp.net/t/1822622.aspx/1
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
leonaisse
Member
40 Points
77 Posts
Re: Using class in masterpage
Nov 28, 2012 11:33 AM|LINK
Thanks Chetan
I have debugged it and its not the master. Ive changed it slightly so that the button click calls a Public Sub in the Masterpage. I can get to the sub but the sub cant find the modal? I'm pretty sure its all a problem with finding the modal.
Modal in basemasterpage
<asp:ContentPlaceHolder ID="mainContent" runat="server"> <asp:Panel ID="emailPanel" runat="server"> <uc:emailPopup ID="ucemailPopup" runat="server" /> </asp:Panel> <cc1:ModalPopupExtender ID="mpuEmail" runat="server" PopupControlID="emailPanel" TargetControlID="btnHdn"></cc1:ModalPopupExtender> <asp:Button ID="btnHdn" runat="server" Text="Button" Visible="False" /> </asp:ContentPlaceHolder>Public sub in basemasterpage code behind (I get a object set to nothing.. error on mpuEmail.show()) Everything else stacks up? So i'm sure this sub cant find the modal. I've tried to use findcontrol but that doesnt find it. Intellisense can find it ok?
Public Sub ShowModal(showHide As String) If showHide = "Show" Then mpuEmail.Show() ElseIf showHide = "Hide" Then mpuEmail.Hide() End If End SubCode on button click in aspx code behind
Dim master1 = TryCast(Me.Master, BaseMasterPage) If master1 IsNot Nothing Then master1.ShowModal("Show") End IfAny further ideas - ive been trying to get this to popup for days. If i move the the modal out of the contentplaceholder it wont hide. Is it becasue the modal is in the contentplaceholder?
Any help would be appreciated.
Thanks
leonaisse
leonaisse
Member
40 Points
77 Posts
Re: Using class in masterpage
Nov 29, 2012 08:57 AM|LINK
I solved this after many days messing around.
Basically I moved the Asp:panel and modal out of the Master pages contentplaceholder and into the main body of the Master page.
I added style="display:none" to the hidden button used as the targetcontrolID for the modal. Setting Visible="False" wouldnt allow the modal to work.
Added a Public Sub to the masterpage (basemasterpage) code behind
Public Sub ShowModal(showHide As String) If showHide = "Show" Then mpuEmail.Show() ElseIf showHide = "Hide" Then mpuEmail.Hide() End If End SubAnd then from my content page could show or hide the modal with
Dim master1 = TryCast(Me.Master, BaseMasterPage) If master1 IsNot Nothing Then master1.ShowModal("Show") End IfIt was that simple!!!!!
Thanks to all that helped!!
Leonaisse