473,387 Members | 1,812 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,387 software developers and data experts.

dynamically writing property values to a control INSIDE of a user control?

I want to use codebehind to pass property values to a control that I've
embedded INSIDE of a user control.

In other words, let's say I have the following:

MyPage.aspx
....with the following control placed on it...
MyUserControl.ascx
.... and inside of MyUserControl.ascx, is an instance of ....
MyCommercialUploadControl1

I want to be able to write a property to the embedded commerical component:
MyCommercialUploadControl1.TargetFolder

I want to be able write this property programmatically from the aspx page
that originally called the instance of MyUserControl, as follows:

[from MyPage.aspx]
MyUserControl.TargetFolder = @"c:\whatever";

Failure #1: I attempted to add logic to the codebehind for my .ascx that
read the value of a property attached to itself, and then mapped that value
to the embedded commercial control, e.g.

MyCommercialUploadControl1.TargetFolder = this.TargetFolder
// "this" refers to the ascx instance

This did not work.

Failure #2: I experimented with various scenarios involving doing the
mappings onPreInit, thinking I might be running into a page lifecycle issue.
This did not work either.

I can successfully write properties to the user control iself, but I haven't
figured out how to write properties to controls INSIDE of the control. In
all cases the debugger indicates null values where i want my properties to
end up. Can anyone help?

Thank you.
-KF

Sep 30 '06 #1
2 1542
In page, you should either embed the value in the HTML tags (ASP.NET tags)
or use Init (not Page Load) to set the value.

In the control, you can be a bit more lax and do not have to aim for Init(),
but it probably will not hurt you.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com/

*************************************************
Think Outside the Box!
*************************************************
<ke*****@nospam.nospamwrote in message
news:Ok**************@TK2MSFTNGP04.phx.gbl...
>I want to use codebehind to pass property values to a control that I've
embedded INSIDE of a user control.

In other words, let's say I have the following:

MyPage.aspx
...with the following control placed on it...
MyUserControl.ascx
... and inside of MyUserControl.ascx, is an instance of ....
MyCommercialUploadControl1

I want to be able to write a property to the embedded commerical
component:
MyCommercialUploadControl1.TargetFolder

I want to be able write this property programmatically from the aspx page
that originally called the instance of MyUserControl, as follows:

[from MyPage.aspx]
MyUserControl.TargetFolder = @"c:\whatever";

Failure #1: I attempted to add logic to the codebehind for my .ascx that
read the value of a property attached to itself, and then mapped that
value to the embedded commercial control, e.g.

MyCommercialUploadControl1.TargetFolder = this.TargetFolder
// "this" refers to the ascx instance

This did not work.

Failure #2: I experimented with various scenarios involving doing the
mappings onPreInit, thinking I might be running into a page lifecycle
issue. This did not work either.

I can successfully write properties to the user control iself, but I
haven't figured out how to write properties to controls INSIDE of the
control. In all cases the debugger indicates null values where i want my
properties to end up. Can anyone help?

Thank you.
-KF

Oct 1 '06 #2
Ah, good, thank you so much. Writing Page_Init() method for the aspx page
indeed solved the problem, like this:

protected void Page_Init()
{
PictureUploaderAndProcessor1.PathVirtual =
"~/ni/apps/xxx/images/submitted/";
}

User controls seem so powerful in allowing you to build parameterized,
generic , reusuable functionality. It's too bad these little gotchas trip up
us newbies. I wonder if there's a way that the VS.NET IDE could cue you to
the right practices: maybe you could help it figure out intent with xml
markup or something.

Anyway, thank you very much. Now to finish my abstracted
uploading-and-image-resizing-and-cataloguing widget. ;)

-KF

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:%2****************@TK2MSFTNGP06.phx.gbl...
In page, you should either embed the value in the HTML tags (ASP.NET tags)
or use Init (not Page Load) to set the value.

In the control, you can be a bit more lax and do not have to aim for
Init(), but it probably will not hurt you.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com/

*************************************************
Think Outside the Box!
*************************************************
<ke*****@nospam.nospamwrote in message
news:Ok**************@TK2MSFTNGP04.phx.gbl...
>>I want to use codebehind to pass property values to a control that I've
embedded INSIDE of a user control.

In other words, let's say I have the following:

MyPage.aspx
...with the following control placed on it...
MyUserControl.ascx
... and inside of MyUserControl.ascx, is an instance of ....
MyCommercialUploadControl1

I want to be able to write a property to the embedded commerical
component:
MyCommercialUploadControl1.TargetFolder

I want to be able write this property programmatically from the aspx page
that originally called the instance of MyUserControl, as follows:

[from MyPage.aspx]
MyUserControl.TargetFolder = @"c:\whatever";

Failure #1: I attempted to add logic to the codebehind for my .ascx that
read the value of a property attached to itself, and then mapped that
value to the embedded commercial control, e.g.

MyCommercialUploadControl1.TargetFolder = this.TargetFolder
// "this" refers to the ascx instance

This did not work.

Failure #2: I experimented with various scenarios involving doing the
mappings onPreInit, thinking I might be running into a page lifecycle
issue. This did not work either.

I can successfully write properties to the user control iself, but I
haven't figured out how to write properties to controls INSIDE of the
control. In all cases the debugger indicates null values where i want my
properties to end up. Can anyone help?

Thank you.
-KF


Oct 1 '06 #3

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

Similar topics

8
by: Mark English | last post by:
I'd like to write a Tkinter app which, given a class, pops up a window(s) with fields for each "attribute" of that class. The user could enter values for the attributes and on closing the window...
1
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that...
0
by: Mark Stokes | last post by:
Hi guys, I have seen various messages on this front, but none specific to my requirement. I have an application that dynamically loads a user control and displays it on the page during the...
6
by: Bhavin | last post by:
Anybody quickly replies it, would be a great help! I try to create dynamic array of textboxes control in ASP.NET(C#). I got the following error while I tried to assign value to ID property of...
0
by: Billy | last post by:
I have a web page with a control (Control#A) on it. The control (#A) has a control (Control#B) on it which displays an exception message when set and displayed. I am creating a simple datagrid...
0
by: Diane Yocom | last post by:
I'm very new to ASP.Net and probably jumped in a little over my head, but... I'm trying to create a user control that will control navigation through my site. It's sortof like Amazon.com, where...
2
by: Web Team | last post by:
Hi All, I'm in the process of writing a eich text editor web custom control. The actual text/HTML is displayed/editied in a DIV layer, which I have created like this: output.Write("<span...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
12
by: vbnewbie | last post by:
I am having problems accessing properties of dynamically generated objects in VB2005. Can someone please help? In a nutshell: My app creates an equal number of checkboxes and labels that share the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.