Set UserControls Visible Property

C

crjunk

I have a web form named MAIN.ASPX with a three UserControls on it -
SideMenu1, CustFields1, and DGCust1.

I have set the visibility property for SideMenu1 and DGCust1 to False.

When the user clicks on a my "Add Record" button from SideMenu1, I
want the usercontrol CustFields1 to become visible.

In the SIDEMENU.ASCX file, I tried adding code TO the On Click event
for the "Add Record" button, to set the usercontrol in MAIN.ASCX to
true, but I can't get this to work.

Can someone give me an example on how to do something like this?

Thanks!
 
K

Ken Cox [Microsoft MVP]

Hi ... (It is polite to include a name when seeking assistance),

In your main.aspx, you need to do two things: Get an instance of the SideMenu
control and its embedded button and add a handler for the button's click event.
The handler points to the code that will respond when the click event happens,
in this case it is Btn_Click().

The code below toggles the visibility of the datagrid on each click of the
button inside SideMenu.

Does this help?

Ken
MVP [ASP.NET]


Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim usrSM As UserControl
Dim btnAddRecord As Button
usrSM = Page.FindControl("SIDEMENU1")
btnAddRecord = usrSM.FindControl("btnAddRecord")
AddHandler btnAddRecord.Click, AddressOf Btn_Click
End Sub

Private Sub Btn_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
Dim usrCF As UserControl
usrCF = Page.FindControl("CustFields1")
usrCF.Visible = Not usrCF.Visible
End Sub



<%@ Control Language="vb" AutoEventWireup="false" Codebehind="SIDEMENU.ASCX.vb"
Inherits="p733workev.SideMenu1"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<p>
<asp:label id="Label1" runat="server">This is SideMenu1</asp:label></p>
<p>
<asp:button id="btnAddRecord" runat="server" text="Add
Record"></asp:button></p>


<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="CustFields.ascx.vb" Inherits="p733workev.CustFields"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:datagrid id="DataGrid1" runat="server"></asp:datagrid>


--
Microsoft MVPs have a question for *you*: Are you patched against the Worm?
http://www.microsoft.com/security/security_bulletins/ms03-026.asp



I have a web form named MAIN.ASPX with a three UserControls on it -
SideMenu1, CustFields1, and DGCust1.

I have set the visibility property for SideMenu1 and DGCust1 to False.

When the user clicks on a my "Add Record" button from SideMenu1, I
want the usercontrol CustFields1 to become visible.

In the SIDEMENU.ASCX file, I tried adding code TO the On Click event
for the "Add Record" button, to set the usercontrol in MAIN.ASCX to
true, but I can't get this to work.

Can someone give me an example on how to do something like this?

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top