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

control1 = control2

I am missing something realy basic here.
If I create a control programmaticly and then assign it to a control that
has already been placed on the page at designe time it does not appear to
render correctly.

example:

I have created a page in the designer with two controls
a label control called lbl1
and a textbox control called tb1

I have the following code in my pageLoad
Dim tbPreset As New TextBox
tbPreset.Text = "hello world"
tb1 = tbPreset
lbl1.Text = tb1.Text
When I run this the textbox is empty BUT the label contains "Hello World"
Can you tell me why this dosnt work?
and how I can make this kind of thing work as I am trying to create a class
that returns a control(a dropdownlist) and then get it to display.

thanx for helping a newbie
Nov 19 '05 #1
4 1029
Basically, what you've done is say that the tb1 control is now something
else. You've set tb1 equal to tbPreset. What is probably happening is now
the tb1 reference is pointing instead to tbPreset, so now when you reference
tb1, you're not getting the control that's on the page, you're getting a
reference to the tbPreset object. The label is fine because the
tbPreset.Text property has something. Even though you set it to equal
tb1.text, you are actually setting it to equal tbPreset.Text since now tb1
and tbPreset point to the same object. Essentially you have a dead control
on the page as tb1 now no longer points to the tb1 that is in the page.
Think of it as setting your telephone to a different phone number, except
now you have no way to answer the old phone number since your phone now
points to some different phone number.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"zebidy" <ze****@discussions.microsoft.com> wrote in message
news:51**********************************@microsof t.com...
I am missing something realy basic here.
If I create a control programmaticly and then assign it to a control that
has already been placed on the page at designe time it does not appear to
render correctly.

example:

I have created a page in the designer with two controls
a label control called lbl1
and a textbox control called tb1

I have the following code in my pageLoad
Dim tbPreset As New TextBox
tbPreset.Text = "hello world"
tb1 = tbPreset
lbl1.Text = tb1.Text
When I run this the textbox is empty BUT the label contains "Hello World"
Can you tell me why this dosnt work?
and how I can make this kind of thing work as I am trying to create a
class
that returns a control(a dropdownlist) and then get it to display.

thanx for helping a newbie

Nov 19 '05 #2
Zebidy:
Nice question :) While I know the answer, it's kinda hard to explain, so
bare with me. tbPresent is a new textbox, when you assign it to tb1 you are
simply changing the reference the tb1 variable points to, but you aren't
actually changing the tb1 control...it still exists on the page and will
still be rendered.

For example, if you modified your code and added a placeholder called plc1:

Dim tbPreset As New TextBox
tbPreset.Text = "hello world"
tb1 = tbPreset
lbl1.Text = tb1.Text
plc1.Controls.Add(tb1)

you'll see that another textbox will be added and this one will have "Hello
World"...so tb1 now points to a new textbox, but the old one still exists
and you haven't changed any of it's properties...you don't see if because
you never add it to the page.

Another way to look at it is:

tb1 = tbPresent
dim oldTb1 as control = Page.FindControl("tb1")
if not oldTb1 is tb1 then
Response.Write("They both exist but tb1 no longer points to where the
actual control tb1, even if it shares it's name")
end if

The above is true...tb1 is no longer oldTb1

hope this helps :)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"zebidy" <ze****@discussions.microsoft.com> wrote in message
news:51**********************************@microsof t.com...
I am missing something realy basic here.
If I create a control programmaticly and then assign it to a control that
has already been placed on the page at designe time it does not appear to
render correctly.

example:

I have created a page in the designer with two controls
a label control called lbl1
and a textbox control called tb1

I have the following code in my pageLoad
Dim tbPreset As New TextBox
tbPreset.Text = "hello world"
tb1 = tbPreset
lbl1.Text = tb1.Text
When I run this the textbox is empty BUT the label contains "Hello World"
Can you tell me why this dosnt work?
and how I can make this kind of thing work as I am trying to create a class that returns a control(a dropdownlist) and then get it to display.

thanx for helping a newbie

Nov 19 '05 #3
Zebidy,

I may lead you down a path you don't want to go but have you tried this?
Dim tbPreset As New TextBox
tbPreset.Text = "hello world"
me.Controls.Add (tbPreset)

You dont need to even have a lbl1 as a placeholder in your html. You can
add objects on your page on the fly.
I use this a lot to dynamically build alot of my pages but I have a named
table structure I use to add the controls. I hope this helps.
"zebidy" <ze****@discussions.microsoft.com> wrote in message
news:51**********************************@microsof t.com...
I am missing something realy basic here.
If I create a control programmaticly and then assign it to a control that
has already been placed on the page at designe time it does not appear to
render correctly.

example:

I have created a page in the designer with two controls
a label control called lbl1
and a textbox control called tb1

I have the following code in my pageLoad
Dim tbPreset As New TextBox
tbPreset.Text = "hello world"
tb1 = tbPreset
lbl1.Text = tb1.Text
When I run this the textbox is empty BUT the label contains "Hello World"
Can you tell me why this dosnt work?
and how I can make this kind of thing work as I am trying to create a class that returns a control(a dropdownlist) and then get it to display.

thanx for helping a newbie

Nov 19 '05 #4
Thanks Steve, Karl and Mark
great responce and so fast..

I was aware of the Control.Add and have used it previously to add
webuserControls on the fly.
I am thinking though it would be nice to keep the designed version of the
page looking like the output so its obvious for those updating the app later.

So I can reference all of the properties of one control to another but not
the control itself.

This is going to make my code a little messier than Id hoped.

thanx again

"zebidy" wrote:
I am missing something realy basic here.
If I create a control programmaticly and then assign it to a control that
has already been placed on the page at designe time it does not appear to
render correctly.

example:

I have created a page in the designer with two controls
a label control called lbl1
and a textbox control called tb1

I have the following code in my pageLoad
Dim tbPreset As New TextBox
tbPreset.Text = "hello world"
tb1 = tbPreset
lbl1.Text = tb1.Text
When I run this the textbox is empty BUT the label contains "Hello World"
Can you tell me why this dosnt work?
and how I can make this kind of thing work as I am trying to create a class
that returns a control(a dropdownlist) and then get it to display.

thanx for helping a newbie

Nov 19 '05 #5

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

Similar topics

5
by: ojvm | last post by:
ok. thanks again for the time spend reading this. this code adds 2 controls in html form but it places in top of the form. i want this control1 control2 control1 control2 control1 ...
0
by: Just Me | last post by:
Given a control1 on a UserControl: After much experimentation I find that the x and y values given to control1.SetBounds(x,y,... needs to have the positions of the scrollbars thumbs subtracted...
3
by: martin | last post by:
Hi, I am attemping to write a composite control but have so far not achieved the results that I am looking for and would appreciate some advice. By a composite control, i mean, a Web User...
3
by: Kevin Swanson | last post by:
I'm writing what should be a very simple app against an Oracle database. The app has a number of user controls, any one of which is loaded into a main display page using the loadControl method,...
6
by: Willie wjb | last post by:
Hi, i have a solution with 4 projects sdk, control1, control2 and controls the sdk is the base control1 uses the sdk control2 uses the sdk controls uses the sdk,control1 and control2
2
by: Gary Shell | last post by:
We are playing around with using the splitter on a form and want to do the following: 1. On the left side of the form will be a tree view. 2. To the right of that tree view would be a splitter....
25
by: Dennis | last post by:
Has anyone really gotten the Docking and Splitter Bars to work for anyting but the simplest application for two controls and one splitter bar filling the whole form? If so, can you enlighten my on...
1
by: Sosh | last post by:
Hi, I'm pulling my hair out trying to work this out. Pehaps I am missunderstanding something - hopefully someone can shed some light on this: 1) I have a class library that contains a bunch...
3
by: JP Romano | last post by:
Hi - I'm putting together a status report summary for a team of about 15 based in the US (various places), London, Hong Kong, etc. The users have expressed interest in using a web form (data access...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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: 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...

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.