Jamie Hartnoll
Jamie Hartnoll

Reputation: 7341

Pass a variable to user control to determine display

Apologies if this is something really simple.

I've found various C# examples here, but I can't seem to get a VB version working.

I want to be able to pass a simple variable into a User Control to determine whether it shows a certain section of data.

It's basically a Customer Data form, and in some circumstances I need to show a line with the customers account number and sort code, and in some I don't, so my user control:

<controls:customerForm ID='customerForm' showBankDetails="no" runat='server' />

But I can't work out what to do with the showBankDetails variable in Code Behind to stop it from rendering that section, or simply hide it with a CSS snippet.

How do I access that variable in the code behind using VB.NET?

Upvotes: 1

Views: 1629

Answers (1)

asawyer
asawyer

Reputation: 17808

Normally I'd have optional stuff in a asp:panel on the page in the right spot, and in the page load or where ever, do something like:

me.OptionalStuffPanel.Visible = me.ShowBankDetails

ShowBankDetails would need to be defined as a public property of the page class:

private _ShowBankDetails as boolean
Public Property ShowBankDetails() As boolean
    Get
        Return _ShowBankDetails
    End Get
    Set(ByVal value As boolean)
        _ShowBankDetails = value
    End Set
End Property

If you want the property to appear in the property grid here is an article to show you how!

http://www.codeproject.com/KB/vb/using_propertygrid.aspx

Upvotes: 3

Related Questions