473,692 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populating Controls - Form Load Dynamically

hi all,
how can I populate one aspx form when page is loading based on page ID? for
example:
loading page A (to search for VB code) would display labels and texboxes,
dropdown lists all related to VB, plus the address bar would show something
like this: www.somethinghere?id=3

and if you change number 3 from the address bar to (for example) 34 or 71
you would get different page with the same formatting like I.e:
www.somethinghere?id=34 would load the page related to C# topics and all
labels and texboxes and dropdown lists related to C# OR
www.somethinghere?id=71 would load the page related to ASP.NET for example
and labels and textboxes would be populated according to ASP.NET and so
on...

my question is, how do they do that? they must assign an ID number for each
topic but then how they populate all controls on that ONE page accordingly?

I am very much interested in this approach and wants to know how its done
and how can I get more info about it. I think its better than duplicating
pages if you were going to use them over and over?

what do you think?

please let me know

thanks
Aug 24 '06 #1
9 7036
id=XX part of the url is available as Request.QuerySt ring.
Request.QuerySt ring["id"] for www.somethinghere?id=71 will return "71".
PageLoad event code can read the id and setup the page controls accordingly.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

"netasp" <ne****@newsgro ups.nospamwrote in message
news:O6******** ******@TK2MSFTN GP02.phx.gbl...
hi all,
how can I populate one aspx form when page is loading based on page ID?
for example:
loading page A (to search for VB code) would display labels and texboxes,
dropdown lists all related to VB, plus the address bar would show
something like this: www.somethinghere?id=3

and if you change number 3 from the address bar to (for example) 34 or 71
you would get different page with the same formatting like I.e:
www.somethinghere?id=34 would load the page related to C# topics and all
labels and texboxes and dropdown lists related to C# OR
www.somethinghere?id=71 would load the page related to ASP.NET for example
and labels and textboxes would be populated according to ASP.NET and so
on...

my question is, how do they do that? they must assign an ID number for
each topic but then how they populate all controls on that ONE page
accordingly?

I am very much interested in this approach and wants to know how its done
and how can I get more info about it. I think its better than duplicating
pages if you were going to use them over and over?

what do you think?

please let me know

thanks


Aug 24 '06 #2
thanks Eliyahu for your reply,

does this method considered to be a good or bad practice with visual studio
2005? because I also have seen some other web applications using different
pages for each category page, their address bar would show aspx pages I.e
employee.aspx, manager.aspx, supervisor.aspx instead of loading everything
into one template page.

I just want to know what is the best practice and recommendation for such a
scenario?

thanks again

"Eliyahu Goldin" <RE************ **************@ mMvVpPsS.orgwro te in
message news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
id=XX part of the url is available as Request.QuerySt ring.
Request.QuerySt ring["id"] for www.somethinghere?id=71 will return "71".
PageLoad event code can read the id and setup the page controls
accordingly.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

"netasp" <ne****@newsgro ups.nospamwrote in message
news:O6******** ******@TK2MSFTN GP02.phx.gbl...
>hi all,
how can I populate one aspx form when page is loading based on page ID?
for example:
loading page A (to search for VB code) would display labels and texboxes,
dropdown lists all related to VB, plus the address bar would show
something like this: www.somethinghere?id=3

and if you change number 3 from the address bar to (for example) 34 or 71
you would get different page with the same formatting like I.e:
www.somethinghere?id=34 would load the page related to C# topics and all
labels and texboxes and dropdown lists related to C# OR
www.somethinghere?id=71 would load the page related to ASP.NET for
example and labels and textboxes would be populated according to ASP.NET
and so on...

my question is, how do they do that? they must assign an ID number for
each topic but then how they populate all controls on that ONE page
accordingly?

I am very much interested in this approach and wants to know how its done
and how can I get more info about it. I think its better than duplicating
pages if you were going to use them over and over?

what do you think?

please let me know

thanks



Aug 24 '06 #3
Hello Netasp,

In ASP.NET, dynamically creating webcontrols is naturally supported. Here
are some web articles introducing this:

#HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# .NET
http://support.microsoft.com/kb/317794/EN-US/

#Adding Controls to a Web Forms Page Programmaticall y
http://authors.aspalliance.com/aspxt...ingcontrolstow
ebformspageprog rammatically.as px

#How to: Add Controls to an ASP.NET Web Page Programmaticall y
http://msdn2.microsoft.com/en-us/library/kyt0fzt1.aspx

for your scenario, you want to generate two page UI for different client
user requests(search for VB or c#), I think you need to consider the
following things:

Which one is more important for our application, flexibiilty or
performance?

When we dynamically create the page UI depend on different client requests,
it make the page very flexible and easy to extend when you want to add
additional UI template(such as search for J#...). However, the drawback
here is that dynamically creating control will add performance overhead
which is less efficient than statically compiled and loaded page/controls.
Also, making the page UI dynamically generated will make the line of code
in your page increase significantly.

IMO, for those pages which as definitely different code logic and business
purpose or the UI differ from each other obviously, I would recommend you
create separate page for each one.

If the UI of those pages are similar and easy to be templated, you can
consider creating a page to dynamically generate UI.

Please feel free to let me know if you have any further questions.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 25 '06 #4
thank you Steven for your reply,

how about this:
I create the page and add all the necessary controls to it, dropdown list,
an image box, labels and some textboxes (with generic names) -// so there is
not an overhead of creating controls dynamically

then, if the user clicks the ASP.NET link for example (and lets say it has
been assigned ID=1) then I go to my database and load the appropriate
control names and images for the C# page! OR if the user clicks C# link
(which lets also assume it has been assigned to ID=21) then I will load from
another table all the appropriate names for labels, textboxes and images for
that C# page.

what do you think? would that cut half of my overhead expenses? considering
the controls are already been created?

I would love to hear your input on this approach.

thank you very much for the links

"Steven Cheng[MSFT]" <st*****@online .microsoft.comw rote in message
news:hp******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hello Netasp,

In ASP.NET, dynamically creating webcontrols is naturally supported. Here
are some web articles introducing this:

#HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# .NET
http://support.microsoft.com/kb/317794/EN-US/

#Adding Controls to a Web Forms Page Programmaticall y
http://authors.aspalliance.com/aspxt...ingcontrolstow
ebformspageprog rammatically.as px

#How to: Add Controls to an ASP.NET Web Page Programmaticall y
http://msdn2.microsoft.com/en-us/library/kyt0fzt1.aspx

for your scenario, you want to generate two page UI for different client
user requests(search for VB or c#), I think you need to consider the
following things:

Which one is more important for our application, flexibiilty or
performance?

When we dynamically create the page UI depend on different client
requests,
it make the page very flexible and easy to extend when you want to add
additional UI template(such as search for J#...). However, the drawback
here is that dynamically creating control will add performance overhead
which is less efficient than statically compiled and loaded page/controls.
Also, making the page UI dynamically generated will make the line of code
in your page increase significantly.

IMO, for those pages which as definitely different code logic and business
purpose or the UI differ from each other obviously, I would recommend you
create separate page for each one.

If the UI of those pages are similar and easy to be templated, you can
consider creating a page to dynamically generate UI.

Please feel free to let me know if you have any further questions.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no
rights.

Aug 25 '06 #5
Thanks for your reply Netasp,

As for the new idea you mentioned, do you mean you predefine all the
controls on the page and assigned fixed ID for each one. and dynamically
load their string resources( such as Text ....) from file or database and
assign to their "Text" property? If this is the case, I think it doable.

Of course, if the controls are defined at design-time, it will save lots of
dynamic control creating and loading overhead.

Please let me know if you have any further questions.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Aug 28 '06 #6
thanks Steven for your reply,

yeah, this is very much the idea, and I think its better than creating more
than one aspx page that does exactly the same thing.

it seems doable so far, and I will pick up any issues as I advance.

thanks for your help.

best regard,

"Steven Cheng[MSFT]" <st*****@online .microsoft.comw rote in message
news:9Q******** ******@TK2MSFTN GXA01.phx.gbl.. .
Thanks for your reply Netasp,

As for the new idea you mentioned, do you mean you predefine all the
controls on the page and assigned fixed ID for each one. and dynamically
load their string resources( such as Text ....) from file or database and
assign to their "Text" property? If this is the case, I think it doable.

Of course, if the controls are defined at design-time, it will save lots
of
dynamic control creating and loading overhead.

Please let me know if you have any further questions.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.


Aug 28 '06 #7
Thanks for the followup Netasp,

Yes, this is a good idea. Actually, what you do is just how ASP.NET
application do localization support for web pages. ASP.NET support creating
resource files for each page or the whole application and we can load
string or other resource(like image, files) from resource file according
different CultureInfo. So for your case here, instead of depending on
CultureInfo, your page's resource are depend on other criteria.

Please feel free to post here if you meet any further problem.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 29 '06 #8
now I have one final question,
what is the best reliable way of loading a control value from a database?
lets say I have label1 already sitting in my webform how can I load its
content "Books" from a table1 in sql 2005 database?

do I use a normal adapter to loop through? is there a good examples
illustrating how to accomplish that?

thanks
"netasp" <ne****@newsgro ups.nospamwrote in message
news:%2******** *******@TK2MSFT NGP02.phx.gbl.. .
thanks Steven for your reply,

yeah, this is very much the idea, and I think its better than creating
more than one aspx page that does exactly the same thing.

it seems doable so far, and I will pick up any issues as I advance.

thanks for your help.

best regard,

"Steven Cheng[MSFT]" <st*****@online .microsoft.comw rote in message
news:9Q******** ******@TK2MSFTN GXA01.phx.gbl.. .
>Thanks for your reply Netasp,

As for the new idea you mentioned, do you mean you predefine all the
controls on the page and assigned fixed ID for each one. and dynamically
load their string resources( such as Text ....) from file or database
and
assign to their "Text" property? If this is the case, I think it
doable.

Of course, if the controls are defined at design-time, it will save lots
of
dynamic control creating and loading overhead.

Please let me know if you have any further questions.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.



Sep 5 '06 #9
Hi Netasp,

how you'll read the static data from database depend on how will you use
them. If you will only load them at each page's startup time and will
requrey database if require them later, I suggest you use Sqlcommand +
DataReader to query the data since this will have better performance.

If you will load the data and also cached them in local memory for later
use, you can consider use TableAdpater and return them in the form of
DataTable, Dataset ....

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Sep 6 '06 #10

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

Similar topics

2
2681
by: Janus | last post by:
Hello. I need a little advice for populating the treeview control. I dont want my application to hang while populating the treeview, there is a lot of data what's the best approach? Maybe something eventbased but how? please help... Should I avoid populating the treeview control using a thread?
7
3256
by: Tim T | last post by:
Hi, I have the need to use dynamically loaded user controls in a webform page. I have the controls loading dynamically, and that part works fine. this is the code used in a webform to dynamically load one of several controls: private void btnCategory_Click(object sender, System.EventArgs e) { Control myControl = LoadControl(DropDownList1.SelectedItem.Text + ".ascx"); PlaceHolder1.Controls.Add(myControl);
8
4311
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image button at runtime: //----- Code snippet protected System.Web.UI.WebControls.PlaceHolder ImageHolder; private void Page_Load(object sender, System.EventArgs e)
1
3017
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am have facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web page dynamically. To do this, First I including a web page (MainPage.aspx) and I made form tag to Runat=Server. I included one table tag and also made this table Runat=Server side. Second I created three Web User Controls e.g....
1
2572
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web page dynamically. To do this, First I including a web page (MainPage.aspx) and I made form tag to Runat=Server. I included one table tag and also made this table Runat=Server side. Second I created three Web User Controls e.g. wucCustomerInfo.ascx,
1
2197
by: Wim | last post by:
Hi Everyone, I'm trying to speed up a Asp.net 1.1 applications' performance. The application needs to run in an environment with little bandwith and therefore pagesizes and roundtrip times shoud be brought back to a minimum. The application suffered from relatively large screens. A typical aspx page was 500 Kbyte so page load times were in the order of 40 - 50 seconds. After unsufficient loading improvement using .net caching
5
2279
by: | last post by:
Trying to learn about manipulating collections of objects, and populating these objects dynamically from datasources. Could someone post a code sample that shows the following: Instantiating a collection object -- say, a dictionary. Populating that collection object with custom objects, say, Person. What I really want to see is how to populate the properties of those Person objects from a datasource: instantiate one Person, fill...
14
2338
by: Joe | last post by:
Hello All: I am trying to dynamically populate a web page with literal content and controls (textboxes and checkboxes (and eventually two buttons - the buttons do not appear in the code yet). I read an xml file and, using the values retrieved from it, determine what text should be displayed and which controls should be rendered and - most importantly - where those controls should be rendered. The ultimate goal is to have some text...
6
1792
by: TB | last post by:
Hi All: I have this page where a rows / cells are programmatically added to to table by pushing a button. The rows contain a textbox and a associated button. What I want to is to be able to add the content of any textbox to a global variable (and a related session variable) when pushing the associate button. However whenever I push the button(s) apparently the session variable
0
8600
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9079
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8954
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8794
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8796
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5817
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4555
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2234
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1955
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.