473,378 Members | 1,542 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.

create a LinkButton at "runntime"

I wish to create some LinkButtons in DotNet. Because I will do it in
dependence of the entries in a database, I can not add them with the mouse
to the form as usually.
I can create them in the Page_Load event but then I can not see them.
I do not know the reason or how to do it correctly.
Do anywhere know something about?
For any help, I thanks a lot
Greetings Patrick Marti
Jul 21 '05 #1
5 1471
Hi Patrick

by "LinkButtons" I assume you are refering to LinkLabels, but anyways it
should work just the same for all controls.... so...
There are a few ways to go about it. If you know from the get go, how many
LinkLabels you will have dynamically created after runtime, you can declare
those controls in your code like this:

private LinkLabel[] _myLinkLabel = new LinkLabel[100]; // declaring 100
link labels

.... then in your code somewhere... depending when you need to create the
labels... say on some other Button you have in your form of which the user
needs to press...

private void SomeButton_Clicked( Object sender, System.EvenHandler e )
{
_myLinkLabel[ _labelCounter ] = new LinkLabel();
_myLinkLabel[ _labelCounter ].Name = "New Label";
_myLinkLabel[ _labelCounter ].Text = "Some text";
..
..
..
// some more code here
..
..
..
}

and that should be it..... UNLESS!!! you have something like a Panel on your
form.... of which will obscure any object under it, if it is not added to
the panel....

so to add a control to a panel...like the link label, you need

SomePanel.Controls.Add( _myLinkLabel[ _labelCounter ] );

then you would probably need to re locate your control so that it is where
you want it to be on your form.

Also... I would recomend using ArrayLists if you don't know how many labels
you will need after runtime. That way you don't really need declare your
label because an ArrayList takes any kind of object... and to access it
later on...to modify it you can either use the Controls property from you
form or the Panel if it belongs to a panel.

hope that helps

"Patrick Marti" <Pa**********@discussions.microsoft.com> wrote in message
news:FA**********************************@microsof t.com...
I wish to create some LinkButtons in DotNet. Because I will do it in
dependence of the entries in a database, I can not add them with the mouse
to the form as usually.
I can create them in the Page_Load event but then I can not see them.
I do not know the reason or how to do it correctly.
Do anywhere know something about?
For any help, I thanks a lot
Greetings Patrick Marti

Jul 21 '05 #2
Hi Felipe
Thanks so much for this huge and really interesting answer!!!
Unfortunately I can try out this at least when I'm at home in the evening.
Anyway, maybe one problem it will exists even longer. I think my object
will not be shown after creating it, but maybe it is because I do it in the
Page_Load event?
I will do some tests more this evening, but it is good to know that it should
work in general.
Again many thanks for your super help
Greetings Patrick

"Felipe" wrote:
Hi Patrick

by "LinkButtons" I assume you are refering to LinkLabels, but anyways it
should work just the same for all controls.... so...
There are a few ways to go about it. If you know from the get go, how many
LinkLabels you will have dynamically created after runtime, you can declare
those controls in your code like this:

private LinkLabel[] _myLinkLabel = new LinkLabel[100]; // declaring 100
link labels

.... then in your code somewhere... depending when you need to create the
labels... say on some other Button you have in your form of which the user
needs to press...

private void SomeButton_Clicked( Object sender, System.EvenHandler e )
{
_myLinkLabel[ _labelCounter ] = new LinkLabel();
_myLinkLabel[ _labelCounter ].Name = "New Label";
_myLinkLabel[ _labelCounter ].Text = "Some text";
..
..
..
// some more code here
..
..
..
}

and that should be it..... UNLESS!!! you have something like a Panel on your
form.... of which will obscure any object under it, if it is not added to
the panel....

so to add a control to a panel...like the link label, you need

SomePanel.Controls.Add( _myLinkLabel[ _labelCounter ] );

then you would probably need to re locate your control so that it is where
you want it to be on your form.

Also... I would recomend using ArrayLists if you don't know how many labels
you will need after runtime. That way you don't really need declare your
label because an ArrayList takes any kind of object... and to access it
later on...to modify it you can either use the Controls property from you
form or the Panel if it belongs to a panel.

hope that helps

"Patrick Marti" <Pa**********@discussions.microsoft.com> wrote in message
news:FA**********************************@microsof t.com...
I wish to create some LinkButtons in DotNet. Because I will do it in
dependence of the entries in a database, I can not add them with the mouse
to the form as usually.
I can create them in the Page_Load event but then I can not see them.
I do not know the reason or how to do it correctly.
Do anywhere know something about?
For any help, I thanks a lot
Greetings Patrick Marti


Jul 21 '05 #3
Hey Patrick,

It should work even if you do it in Page_Load as long as you remember to add
the controls to the Controls collection of either the form or any other
control already on the form. However, you may run into some issues regarding
viewstate when adding the controls in Page_Load. Because of this the OnInit
override in your form may be a better place to do it.

Regards, Jakob.

"Patrick Marti" wrote:
Hi Felipe
Thanks so much for this huge and really interesting answer!!!
Unfortunately I can try out this at least when I'm at home in the evening.
Anyway, maybe one problem it will exists even longer. I think my object
will not be shown after creating it, but maybe it is because I do it in the
Page_Load event?
I will do some tests more this evening, but it is good to know that it should
work in general.
Again many thanks for your super help
Greetings Patrick

"Felipe" wrote:
Hi Patrick

by "LinkButtons" I assume you are refering to LinkLabels, but anyways it
should work just the same for all controls.... so...
There are a few ways to go about it. If you know from the get go, how many
LinkLabels you will have dynamically created after runtime, you can declare
those controls in your code like this:

private LinkLabel[] _myLinkLabel = new LinkLabel[100]; // declaring 100
link labels

.... then in your code somewhere... depending when you need to create the
labels... say on some other Button you have in your form of which the user
needs to press...

private void SomeButton_Clicked( Object sender, System.EvenHandler e )
{
_myLinkLabel[ _labelCounter ] = new LinkLabel();
_myLinkLabel[ _labelCounter ].Name = "New Label";
_myLinkLabel[ _labelCounter ].Text = "Some text";
..
..
..
// some more code here
..
..
..
}

and that should be it..... UNLESS!!! you have something like a Panel on your
form.... of which will obscure any object under it, if it is not added to
the panel....

so to add a control to a panel...like the link label, you need

SomePanel.Controls.Add( _myLinkLabel[ _labelCounter ] );

then you would probably need to re locate your control so that it is where
you want it to be on your form.

Also... I would recomend using ArrayLists if you don't know how many labels
you will need after runtime. That way you don't really need declare your
label because an ArrayList takes any kind of object... and to access it
later on...to modify it you can either use the Controls property from you
form or the Panel if it belongs to a panel.

hope that helps

"Patrick Marti" <Pa**********@discussions.microsoft.com> wrote in message
news:FA**********************************@microsof t.com...
I wish to create some LinkButtons in DotNet. Because I will do it in
dependence of the entries in a database, I can not add them with the mouse
to the form as usually.
I can create them in the Page_Load event but then I can not see them.
I do not know the reason or how to do it correctly.
Do anywhere know something about?
For any help, I thanks a lot
Greetings Patrick Marti


Jul 21 '05 #4
I found a good article yesterday that shows how to do something similar and
also explains the viewstate considerations:

http://www.codeproject.com/aspnet/retainingstate.asp

HTH

"Patrick Marti" wrote:
I wish to create some LinkButtons in DotNet. Because I will do it in
dependence of the entries in a database, I can not add them with the mouse
to the form as usually.
I can create them in the Page_Load event but then I can not see them.
I do not know the reason or how to do it correctly.
Do anywhere know something about?
For any help, I thanks a lot
Greetings Patrick Marti

Jul 21 '05 #5
So good!!!
Thanks everybody for help in this.
I could not test it until now, but I'm shure it will work.
Have a good time
Greetings Patrick
"rufus" wrote:
I found a good article yesterday that shows how to do something similar and
also explains the viewstate considerations:

http://www.codeproject.com/aspnet/retainingstate.asp

HTH

"Patrick Marti" wrote:
I wish to create some LinkButtons in DotNet. Because I will do it in
dependence of the entries in a database, I can not add them with the mouse
to the form as usually.
I can create them in the Page_Load event but then I can not see them.
I do not know the reason or how to do it correctly.
Do anywhere know something about?
For any help, I thanks a lot
Greetings Patrick Marti

Jul 21 '05 #6

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

Similar topics

5
by: Patrick Marti | last post by:
I wish to create some LinkButtons in DotNet. Because I will do it in dependence of the entries in a database, I can not add them with the mouse to the form as usually. I can create them in the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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.