473,396 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

User Control Trouble with Runtime Property

I am having trouble accessing a property set during run-time in a user
control that I have built. The control is supposed to connect to a
database using the path supplied by the developer at runtime. Any
assistance would be greatly appreciated. The code is as follows:

In the class I declared the private variable strDatabasePath
public partial class UserControl1 : UserControl
{ //... other code

private string strDatabasePath;

//... other code
}
I created the DatabasePath accessor to store the user input from
design-time into the variable. The property shows up in the User
Control's property window.
[Browsable(true), Category("Database"),
DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),
DefaultValue(true),
Description("Sets and gets the database path.")]
public string DatabasePath
{
get
{
return strDatabasePath;

}
set
{
strDatabasePath = value;

}

}

In the load method I attempt to use the strDatabasePath variable to
access database.The variable is always set to null when I check it in
the debugger whether I set it in the property window during design time
or not.
private void UserControl1_Load(object sender, EventArgs e)
{
//... other code

//Establish Connection to the Database
MyDbConnect = new DataConnect(strDatabasePath);

//... other code

}

Jul 31 '06 #1
3 1735
Have a look in initializecomponent; since you seem to be using 2.0 this
will be in the .designer.cs; I suspect that the property value is never
being written to the source code (?is it there if you save the project,
close the IDE and reload it?).

The reason I think is the [DefaultValue(true)]; since the property is
typed as a string, this should probably be [DefaultValue("")], with
matching field initializer:

private string strDatabasePath = "";

The designer checks the value of [DefaultValue(x)], compares it to the
current value, and writes code if it is different; the illegal bool /
string cast is probably throwing it (although it would be nice if it
failed-safe, and acted as though [DefaultValue(x)] had not been
applied, i.e. wrote the value /all/ the time...

Let me know if this helps (I haven't done any tests, so this is all
on-a-maybe...)

Marc

Aug 1 '06 #2
Right theory, wrong attribute; it is the DesignerSerializationVisibility
that is the problem; either remove this or set it to visible, and everything
works.

Marc

(PS: for ref (from my last post) the runtime /does/ failsafe for bad
[DefaultValue(x)] as I suggested it should...)
Aug 1 '06 #3
Thanks Marc... That did the trick.

David Ricketts

Aug 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
4
by: Andrea Williams | last post by:
I'm trying to set up a user control and change some values from the aspx page, but I keep running into trouble. What I really would like to do is be able to set a Label.Text in the user control...
0
by: Jeff Schaefer | last post by:
What I want to know is this: Is it possible to programmatically manipulate a custom property of a user control for which <%@ OutputCache ... > has been included? If so, then how? My brief code is...
7
by: Smithers | last post by:
I have a non trivial ASP.NET Web application that implements its navigation system via a user control (menu.ascx) placed on every page. It is important to note that the user control that hosts...
0
by: Tom | last post by:
I am having a really annoying issue with serialization and a .NET User Control I am writing. For example, let's say I have a couple of classes in my control - first class is like: Public Class...
5
by: c676228 | last post by:
Hi, I guess I am confused. In aspx script, I mean (you won't use Codebehind="enrollinfo.aspx.vb", but mix code with html and code together) You can access user control's property directly. Since I...
3
by: c676228 | last post by:
Hi all, If I developed a phone user control which has requiredfieldvalidator, regularexpressionvalidator etc. The quesiton is if on a web form which have three phone fields and only any one of...
2
by: David Veeneman | last post by:
I'm having trouble implementing a UserControl base property in a user control that I am writing. My user control wraps a group box that contains several radio buttons. I want to wire the user...
9
by: keith | last post by:
I use this code to load a user control at runtime: Control c = Page.LoadControl(Request.ApplicationPath + "/User_Controls/website_design.ascx"); UserControlPlaceHolder.Controls.Add(c); ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.