473,480 Members | 3,062 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Visual Studio/ASP.net and C# confusion

I have a page, default.aspx.cs that instantiates a label, label1 and
adds some properties to the label:

Label Label1 = new Label();
this.Controls.Add(Label1);
Label1.BackColor = System.Drawing.Color.Pink;
Label1.Text = "Lefantze test: _Default class";

===============
On the default.aspx page, the html is as follows:

<asp:Label ID="Label1" Text="Ranginald" BorderColor="Gold"
runat="server" Width="266px" BorderWidth="10px"></asp:Label></div>
</form>

When I compile and run the page, I have two textboxes -- and they are
both label1.
Why is this happening? I thought there could be only one control with
the name label1?
(Note that in design view, only one label is shown and that's the one
in the html)

Thanks!

May 6 '06 #1
6 1167
V
Hi,

1. When you run, you should have 2 Labels (not two text boxes).
2. You are supposed to have 2 text boxes. One is created because of the
code in the html part of your page at design time, and the other is
created because of the code you wrote in the code-behind.
3. The reason for why you apparently have two controls both called
'Label1' is that when you create a control from code (at runtime), the
ID is auto-generated. The Label1 in your code is just the variable name
and not the ID.
4. When you page is running, try to do a view html source and then you
will notice that the IDs for both the controls are actually different.

Regards,
Vaibhav

May 7 '06 #2
Thanks for your response.

1. Is it possible to add properties to a control, say Label2,
programatically as well as via the properties window in design view.

2. If I have a method, createTextBox() that is called in the Page_Load
of default.aspx, and has an onClick method of doSomething(), what is
the best way to inherit this methoed createTextBox() method into
another page with another class.

I can do it with a label without a problem, but everything seems to
change with a control such as a listbox.

Thanks again.

May 7 '06 #3
V
Hello,

My responses below:
1. Yes, it is possible to add properties to a control programmatically
as well as via the properties windows. However, there are certain
properties which can only be changed at design time and others which
can only be changed at run-time. You need to look up the documentation
for whichever class/control you are working with.

2. I am not too sure what you are trying to do here. If you want to
dynamically add a control to your page and reuse the code you have
written to do that, then yes you can. I will need some more explanation
of what you are trying to achieve.

Regards,
Vaibhav

May 7 '06 #4
Here's the plan:

I am working on a project and I want to have two drop down lists on the
left side of the page. These are ddlCategory and ddlSculpture. On the
OnSelectedIndexChanged the controls head to runCategory() and
runSculpture() respectively.

This area is to be locked with a template so I can reuse this
navigation on all pages.

The content section of each page (basically a big editable table in the
middle) will obviously be different for each page. In the
sculpture.aspx page, for example, in the body section there is a
datagrid that does its own thing and has its own code.

I was told that I should try to use inheritance so that each page can
easily use the template, but after weeks of struggling, I have
unfortunately resigned to just copying the code for the drop down lists
and their executing methods to each page of the site.

I've made a lot of posts, and the post above was to try and get a
simplified model going so I could try to make sense of all of this. I
tried to do it with each page having a separate .cs page, but had
namespace issues. Then tried to put all the code into one .cs page
with different classes to keep things clean. I then run into
inheritance trouble.

I know it defeats the whole purpose, but at least at this point all of
the pages have their own .cs code file so the code is still separate
from the presentation layer. There are only seven or do pages in the
whole site, three of which are dynamically generated from a MSSQL
database.

If you have the time and want to take a peek, I've posted the code
elsewhere:

in microsoft.public.dotnet.languages.csharp --
Beginner - basic inheritance problem -- public/protected

The whole code is a few post down.

Thanks in advance for your help so far. I really appreciate it!

May 7 '06 #5
V
Hello,

I have been away (a lot of work in the office).... If you are still at
the same point in your problem, please let me know, then i will start
working with you again.

Regards,
Vaibhav

May 10 '06 #6
Thanks. As it is I am still at the same point. Any help is greatly
appreciated.

-David

May 10 '06 #7

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

Similar topics

10
2466
by: FLChamp | last post by:
SOrry if this message is a little confused, it most probably reflects the state of the author! I have made a small program that plots the orbit of a planet in visual python using visual.vector...
30
2174
by: Cowboy \(Gregory A. Beamer\) | last post by:
There seems to be a lot of confusion on the versions of Visual Studio 2005. My latest blog entry covers the different versions: Main URL:...
17
2552
by: Andi Plotsky | last post by:
I am not a .NET developer. I want the Developer's Edition of Visual Studio for use with my Access2000 databases. Does anyone have a clue as to where to find it - my office manager says only .NET...
11
6801
by: olle | last post by:
Hi everyone. I am an Access developer having worked with Access-dev. projects for many years on Sql server databases and Access. For the internet I have been using traditional asp. But now I have...
21
2002
by: Paul Tremblay | last post by:
Hi All, I am a veteran C/C++ programmer (Unix background) and I want to get to speed with Visual Studio .Net I have legacy C/C++ code that I want to use in my application. However, I'm not...
10
3661
by: Jordan | last post by:
I would like to take my ASP.NET project to another computer, which doesn't have Visual Studio. If I modify the code there, is there a way to recompile it without Visual Studio? Thanks!
2
965
by: Supra | last post by:
Finally Visual Studio 2005 launch date was announced at VS Live and we should be getting our hands on final product on Nov 07, 2005. It reminds me, I just installed Visual Studio 2005 Beta 2....
11
2269
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I have seen the terms Visual Basic 2005 and VB.NET. It seems that sometimes they seem to be referring to the same thing but sometimes they are not. I also run into terms like VB9 and VB10.
33
2832
by: Ioannis Vranos | last post by:
A bit off topic, but does anyone know if Visual C++ 6 supports the 9899:1995, or only the 9899:1990?
4
3275
by: Miro | last post by:
<i have also added this reply to the other newsgroup - now that I have realizd ( and assuming ) it is not a localized error directly to vb.> I have found this link on the website:...
0
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6920
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
7060
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7106
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...
1
6760
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7022
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
4501
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3004
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.