Web User Control Default Property Value

I have a Web User Control (not a custom Server Control) on my page and I have a property set:

        Public Property Enable_Export() As Boolean
            End Get
(ByVal value As Boolean)
                Export = value
            End Set
        End Property

I want "False" to show as the default value for this property in my Properties Window when the control is in design mode but I can not figure out how.  I have tried adding DefaultSettingValue("False")> before the property but this does not work.

Can this be done for a Web User Control or does it only work on Custom Server Controls?

7/27/2007 12:48:38 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

7 Replies

Similar Articles

[PageSpeed] 50

Try setting Export=false

You will get this default value at runtime as false.


Note: Please don't forget to Mark the "Answer" for the post which helps you.
7/27/2007 2:55:16 PM

Specifically, set it in the Page_Load sub (not in the Get portion of the property).

I apologize if that was obvious, but somebody somewhere would have misinterpreted it... 

Peter Brunone
Founder, EasyListBox.com
Do the impossible, and go home early.
7/27/2007 3:17:26 PM

Hmmm... Check this article out

http://support.microsoft.com/kb/161208 ... dont really know what the heck this is talking about...  But this is more of what Im use to seeing


    ' Set ControlValueProperty attribute to specify the default
' property of this control that a ControlParameter object
' binds to at run time.
<DefaultProperty("Text"), ControlValueProperty("Text", "DefaultText")> Public Class SimpleCustomControl
Inherits System.Web.UI.WebControls.WebControl

Dim _text As String

<Bindable(True), Category("Appearance"), DefaultValue("")> Property [Text]() As String
Return _text
End Get

Set(ByVal Value As String)
_text = Value
End Set
End Property

Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
End Sub

End Class

 The default value attribute is what you interested in, well and the design mode declaration at your  class level.

7/27/2007 3:26:56 PM

Set it where u declare it

Dim Export as Boolean = false

Note: Please don't forget to Mark the "Answer" for the post which helps you.
7/27/2007 5:16:11 PM

This appears to only work for User Controls, not for Custom Web Controls. 

The suggetions above concern the values as run time.  I want the default value to appear in the properties window in design view.

7/30/2007 3:26:34 PM


This appears to only work for User Controls, not for Custom Web Controls. 

The suggetions above concern the values as run time.  I want the default value to appear in the properties window in design view.

Hi KerrAVon,

Check out this link:


Hope it helps,

Hong Gang

Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
8/3/2007 3:34:12 AM

Hi, I've just got this working for my Web User Control using this code. I hope it's of some help to people. (Note the imports statement at the top). Ryan


Imports System.ComponentModel

Partial Public Class EditBuyersGuide
    Inherits System.Web.UI.UserControl

#Region "Properties"

    Private _ReadOnly As Boolean = True
    <DefaultValue("True")> _
    Public Property [ReadOnly]() As Boolean
            Return _ReadOnly
        End Get
        Set(ByVal value As Boolean)
            _ReadOnly = value
        End Set
    End Property

#End Region

End Class
9/2/2008 10:09:21 AM

Similar Artilces:

Retreiving a value from a web form within a web user control
Hi  I have a page (web form) that retreives some data from a database. To be more specific: at some point when user clicks a button (in the web form) there is some ID number retreived from a database in code behind. At the same time the Visible property of the nestet web user control is chamged to true. I want than forward the ID to the web user control so that a grid view can load data from a database for that ID. How can I access that data (the ID) within a web user control context nested in that page?  Kind regards   Check this ;ink  http://www.codeproject.com/K...

Web User Control to Web User Control...
Hi, I have 2 User controls on a page and want Control1 to call a method of Control2. Is this Possible? Example: Con1 = Datalist showing products, each with a Quantity Box and a Button. Con2 = Repeater showing Cart Preview (name, Price) in page.aspx. When I click on the button on the DataList in Con1 it adds the item into the Session based Cart. However it does not update the Cart Preview. I need to call BindPreview() in Con2 in order to update the Cart Preview... Does that make sense? argh! any help much appreciated! PeteWeb Design Nottingham, UK Well I can call BindPreview() from m...

Using property values of user control between two web forms.
Hi,I am stuck with a problem.I have a user control on more than one web form( say webform1 and webform2 ).The user control consists of several hyperlinks(say hyp1 and hyp2 ).When I enter values in webform1 and then click 'save' button , one of the property of user control (say ID ) is assigned some value. I want to use that value 'ID' in webform2 after the user clicks on hyp2. I dont think using Querystring will be useful because hyp1 is selected be default. It is not a compulsion for the user, that he has to click on hyp2..he can also click on other hyperlinks of the user control also...Ple...

Web Form and Web User Control
Hello, I have a Web User Control (ascx) that includes a button. This button has an onclick event method. This Web User control is included into a Web Form. (thru LoadControl). However, when I click on the button, the event method is not executed. What should I include in order it works fine? Thanks in advance. GAA. Using Loadcontrol is using dynamic controls and when using dynamic controls you must recreate the same dynamic controls ono postback to econstruct the page control tree. It is best if you do this during the Page PreInit event. How complex are your controls ...

access controls on web user control x from web user control Y
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes on web user control X from web user control Y and I also would like to know how to access functions that are on a web user control X from a web user control Y, is this possible? How can I do it? User can access and set the values of the User Control from .aspx page through properties,using javascript and in code-behind of aspx page.The details of it are shown below Using PropertiesIf the Sample.ascx control has two textboxes and submit button.You can access the valu...

Web User Control Not rendering in Web Form
I have created a Web User control that is made up of a Multiview with 2 views inside the Multiview. I have buttons on both views and a gridview on 1 view. My question is when I drop this Web User Control on a Web Form all I see is [MultiView"MultiView1"] and when I view the from in the browser I dont see the Web User Control. I was wondering if someone could please tell me why the Web User Control is not displaying or rendering.     Thanks In Advance Hi, Please check your aspx file for correct reference, like following example: TestControl.ascx:<%@ Control ...

Clearing Web Controls Values from a Web Form
I have a web form and after a user submit it I want to clear the form so that they may submit another entry. I have seen examples in VB of how to loop thru a web form and clear the controls, but I need a C# solution. I have tried the following code, while it does not give me an error, it does not clear the controls on the form. Any suggestions? Thanks! foreach (Control parent in Page.Controls)         {             foreach (Control child in parent.Controls)           ...

custom web user control and web form
Guys,          I am trying to develop a context menu control for all of my pages. what i am trying to do is that i want the control to pick a datasource from the markup and then check whether its an xml file or a datatable. I created a class called datasource.   /**************************DataSource Class****************************/  public class DataSource { /// <summary> /// This is to identify unique elements from the markup /// </summary>protected string _ID; /// <summary> /// This will be the Datasource ID e...

web controls and web user control
i have a problem in a web form , I have a webform that contains a web user control which in turn contains a html input form ,the web control events don't fire up ,When I click button ,no effect ,I don't know what is the effect of the html form which is in the web user control on the web controls in the web form ?? can any one help me the web control event should be handle in the code behind page, is the event handler for the button you are clicking registered? You can try double clicking the button, should give you the default btn_click event handler in code behind. Also, make ...

Access a Web User Control Method from a Web Form
I'm trying to pass the Selected Index value from a web user control in a web form to the user controls selectedIndexchanged Sub.  I can't seem to figure out how to pass the information that I need to the user control and have it execute the sub routine. In the SelectedInedxChanged Sub I have a switch Statement and I want to get the index value from the web form where the user control is located and compare it to each case and then to have it execute the code for the case that it matches. What do I need to do? Hi, I am not sure if I understood your question correctly. I su...

Access SqlDataSource on Web Form from a Web User Control...
Hello, I want to access a SqlDataSource on a Web Form fromout. a Web User Control. To do this, I have in my code behind of the Web User Control the folowing code: DropDownList1.DataSource = (this.Page.FindControl("SqlDataSource3") as SqlDataSource);DropDownList1.DataTextField = "Name;DropDownList1.DataValueField = "NameIDropDownList1.DataBind(); But, the control (ic. SqlDataSource3) is not found. Even other controls like labels and buttons are not found with the FindControl. What am I doing wrong? Thanks Andromedaris     This is not much of a surprise,...

validate Textbox in Web User Control from web form?
ASP.NET 2.0 I have a web user control that contains a textbox.  I need to add some validation (like requiredfieldvalidator, comparevalidator, etc). I would normally add the validator to my web user control by placing the validator next to my textbox.  However, I need the validation message somewhere else on my web form, not near the user control. So how would I associate a validation control on my web form with the text box inside my web user control?  Can this be done; any alternatives out there? Thanks!   The error message should occur wherever you place the vali...

Interaction between Web User Control & Web form
Ok, I want to create my first Web User Control which is used for file uploading. It's very simple, consist only of the <asp:FileUpload> and <asp:Button> control. The button has one server side event which is resizing the uploaded image to two different images (stored as byte[] in the cs file). So, my question is how I can send these two arrays of type byte to the Web form where the web user control is inside. I thought it should be possible to write something like this in the Web form:<uc1:FileUploader ID="uploader" runat="server" OnUploaded="recieveImages" />So that means ...

Pass data from Web User Control to Web Form
I have a Web Form that contains a Web User Control. The WUC displays dynamic content. I want to change the TITLE property of the Web Form, based on the contents of the WUC. For example, if the WUC displays information about Horses, I want to change the page title to "HORSES" by passing the string to the parent Web Form. I have tried playing with parameters and such, but I can't remember how I did this in the past. PLEASE HELP!~o0 Spin-Monkey Oo~ The best way to do this is by creating a public property on your web user control and accessing that from your web form. Check ...

Web resources about - Web User Control Default Property Value - asp.net.web-forms

Property - Wikipedia, the free encyclopedia
In abstraction, property is that which belongs to or with something, whether as an attribute or as a component of said thing. For the significant ...

Property - Wikipedia, the free encyclopedia
This article may require copy editing for grammar, style, cohesion, tone, or spelling . You can assist by editing it . In abstract, property ...

Confusion reigns as short-term rentals through Airbnb carry high cost for property owners
Mary&nbsp;Banfield was opening up her Surry Hills terrace to short-term stays. Then the council fee arrived.

Sun shines as Lang Walker contemplates Australia's largest property deal
Lang Walker is sipping a gin and tonic watching the sunset on a beach in Fiji as he talks about what will be the largest single property sale ...

China stocks rise, led by property shares - DailyTelegraph Search Search
CHINA stocks have climbed, led by property and resources shares, amid signs that insurers are scrambling for stakes in real estate majors and ...

Sydney real estate - Northern beaches property wins surge in interest from Chinese buyers
SUBURBS in Sydney’s northern beaches are gaining elevated interest among ethnic Chinese property buyers, according to a major international online ...

Basics key to selling Perth property, says new report - PerthNow Search Search
HOMES with water views might net a million-dollar return, but practical features such as a double lockup garage and a short commute to work make ...

$863m stamp duty windfall for NSW Government on back of asset sales and property
The Baird government is expecting a massive stamp duty bonanza but warn it may be the last for some time as the property market cools.

Men face court after $30,000 worth of suspected stolen property seized in Griffith
Two men are set to face the ACT Magistrates Court on Saturday morning in relation to stolen property and burglary charges.

Vandals spray-paint Hawthorne mosques, leave fake grenade on property
Two mosques in Hawthorne were vandalized and police say both incidents are being investigated as hate crimes.

Resources last updated: 12/17/2015 9:59:27 AM