Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Visable property of a usercontrol ASP:Button 1

Status
Not open for further replies.

MdotButler

Programmer
Jan 18, 2006
104
US
I have a button on a Usercontrol placed on many pages.

When I am in inquiry mode I want this button visable and not visable when in add or edit mode. Before making the common code a usercontrol I would address the button directly in the code behind as such:
Code:
btnCompanyDetail.Visable = True | False
I placed the user control onto the new page as such:
Code:
<uc1:CompanyHeader ID="CompanyHeader1" runat="server" />
How do I now address this button from the parent page code behind?

Mark
 
have you tried:
CompanyHeader1.btnCompanyDetail.Visable = True | False
 
I have tried it and I get the following error:
Code:
'ASP.WebUserControl.Protected Dim WithEvents btnCompanyDetail As System.Web.UI.WebControls.Button' is not accessible in this context because it is 'Protected'.
Now the answer may be in the error but it is foreign to me. Does that help anyone on addressing the control?

Mark
 
What would I set to "Friend" or how do I set a usercontrol to "Friend" The button is defined within the usercontrol as an ASP:Button.
Code:
<asp:Button ID="btnCompanyDetail" runat="server" CausesValidation="False" Text="Company Detail" />
 
inside of CompanyHeader1 you have dimentioned btnCompanyDetail as a private object. instead of using "Dim" or "Private", try using "Friend btnCompanyDetail ..."

Does that make and sense to you?

Senior Software Developer
 
Inside of CompanyHeader1 I have defined the button as in the previous post. I have not DIM'd any variables. I am trying to reference the button property directly.
 
1. What version of the framework are you using?
2. Please show the souce(HTML view) of the user control
3. Please show the code of how the user control is instantiated on the page it is being used.
 
Thanx for the response. Here are the answers I think you are looking for.

I am using asp.net 2...

Following is the way the usercontrol is included in the .aspx code:
Code:
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Employee_E.aspx.vb" Inherits="Employee_E" %>
<%@ Register Src="CompanyHeader.ascx" TagName="CompanyHeader" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="pageheader" Runat="Server">
Maintenance Form
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Content" Runat="Server">

<uc1:CompanyHeader ID="CompanyHeader1" runat="server" />
...
The generated HTML (for just the button in question) is as follows:
Code:
<input type="submit" name="ctl00$Content$CompanyHeader1$btnCompanyDetail" value="Company Detail" id="ctl00_Content_CompanyHeader1_btnCompanyDetail" />
I am not sure what you mean in question 3 unless you mean how it was included in the .aspx source as illustrated above.

In the codebehind I have never before had to concern myself with the generated names (code). I have always referrenced the asp.button id. The code in the usercontrol used to be inline code and I referrenced the button without a problem. It is that now it is within the usercontrol container that I cannot referrence the button.
 
What I would do is create a Public Property (with a type of Boolean) in your user control. You will then be able to access the property of user control and set it to True/False. In the set method of the property, you can simply set the Button's Visible property.


------------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top