.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan
Post New Web Links

Dynamically adding User Controls -- newbie question!

Posted By:      Posted Date: September 05, 2010    Points: 0   Category :ASP.Net
 
I am new to ASP.NET (coming from ColdFusion, thank goodness I'm away from that!).  And I am have THE hardest time understanding how to work with forms in ASP.NET.  Here's what I am doing:Dynamically add User Controls to a PlaceHolder based on some int value (which currently is passed in a HiddenField).Fire an event if the WebControls inside of the User Control change, then handle that event in the Main Page (i.e. save the input to DB)When the user clicks the "Next/Continue" button, the next controls for the next page are loaded.And I guess maybe I just can't seem to get how things work in ASP.NET, because I am really struggling with the general idea of how ASP.NET flows.  Should I be dynamically loading the controls in Page_Init, or Page_Load?  Or should I load the controls when the buttonclick event is fired?Do I have to add the axCtrl.OnDataChange += new EventHandler(HandleAxControlDataChange); line on Page_Load?  Or should I put this in When I first load the UserControl, I need to initialize some WebControls within the UserContorl.  Is there a way to know if I have loaded new user controls into my placeholder?  I can't use Page.IsPostback, because after the first page, every page is a postback from the buttonclick.Any help for this confused newbie would be GREATLY appreciated!!Here's what I have: pu


View Complete Post


More Related Resource Links

Advanced Basics: Adding New Features with User Controls

  

In past versions of Visual Basic, there were rudimentary graphics controls. In Visual Basic .NET you have the GDI+ library, which enables you to draw lines, circles, and most anything else. But how can you use the functionality of GDI+ to create lines and other graphics that respond to user mouse clicks and events? Find out.

Ken Spencer

MSDN Magazine June 2003


Adding carriage returns between 2 dynamically created controls in an HtmlTableCell

  

The title pretty much explains it. Here is what i'm trying to do...

 Private Sub LoadGrid_CommentsField(ByVal Row As HtmlTableRow, ByVal BookingNumber As String, ByVal CommentsText As String)
  Dim Txt As TextBox
  Dim Cmd As ClickOnceButton.ClickOnceButton

  Txt = New TextBox
  Txt.ID = "txtComment_" & BookingNumber
  Txt.CssClass = "TFAppControls"
  Txt.TextMode = TextBoxMode.MultiLine
  Txt.MaxLength = 500
  Txt.Width = New Unit(95, UnitType.Percentage)
  Txt.Text = CommentsText
  Row.Cells(cComments).Controls.Add(Txt)

  Row.Cells(cComments).InnerHtml &= "<br/>"

  Cmd = New ClickOnceButton.ClickOnceButton
  Cmd.DisableAfterClick = True
  Cmd.Text = "Save Comments"
  Cmd.ID = "cmdSaveComments_" & BookingNumber
  Cmd.CssClass = "TFAppButtons"
  Cmd.EnableViewState = False
  Row.Cells(cComments).Controls.Add(Cmd)
 End Sub

On the line where i try and update the InnerHtml, i get the following error; "Cannot get inner content of  because the contents are not literal."


How to dynamically create user controls ?

  

HI,

can you explain how to create user control dynamically in a web form ?When i am creating server controls of user controls are not instantiated and it is not getting initialized .when i am tyying to initialize its properties error occurs tha object instance not created .

Any suggestion ? 


Enable/Disable controls dynamically based on User settings

  
In my project I have a requirement that all controls in each window shall be enabled or visible dependent on user and the admin shall be able to change is a user will be able to use or see the control. I made a very simple test application that creates a user and gives him a list (will be loaded from db in real app) of the name of the controls in the window and also his settings. Then after initializing the window I use reflection to find the controls and set their isenabled/visibility properties. This solution does the thing but I'm wondering if there is a better solution. The main issue here is that each control must be set per user and thus roles wont work appropriate and also that I need to be able to change the settings at runtime.  

Question about adding ASP.NET controls to the page later on via programming logic

  

Hi,

I'm pretty new to ASP.NET as you'd expect and I'm coming from a PHP scripting background. I am understanding ASP.NET development so far, however, say you have added many controls onto the web page and later on you want to remove a specific block of controls and add new ones, and this is via programming logic (the backend VB file), how would you go about doing this? Or would you have to go for the approach of adding these controls in a container to the web page first - making them invisible - until you need to use them in your programming logic?

Thanks,

Ben.


newbie question: change login name of dbo user

  

My database has a user "dbo" which is dbo of all database objects. The login name for this user is e.g. "Login1". Now I need to change the login name for user "dbo" from "Login1" to a new login name "Login2".

It is not possible to change the related login name of the user "dbo" in the user's properties dialog. And it is also not possible to change or remove the dbo relation in the login name's properties dialog (because a dbo user can not be removed).

Is there any possibility to change the login name of an dbo user? How can I do it?


Adding Controls dynamically in the infopath form - A standard Expense Entry scenario

  

Hi,

I am having a requirement where I need to create an Expense Report Entry form using Infopath 2010. 

1) The form would have pre-defined columns/Controls like Exp.Type(drop-down) , Details , Location, Amount , Curruncy, Date etc..

2) User can enter/update as many line items as possible by clicking Add/Update/Delete for the each line items. So basically its like adding the same row dynamically.

3) When User Submits, I need to capture this data and post it to SAP where I am using SAP web Services.

Can you please suggest if this is possible in InfoPath form ?

If Yes, how can I achieve this dynamic line items functionality in InfoPath

And how can I read the data using the code so that I can Post it to the WebService? 


Newbie User Import Question re: One way external trust & Security

  

Hello.

There is a business initiative to install a Dev Sharepoint 2007 server in our Trusting Domain. My internal corp network will be Corp.COM. The 3rd party network will be 3rd.COM.  Currently 3rd.COM has a Oneway External Trust pointing inward to Corp.com.  Corp.COM Domain and Forest levels are WIndows 2003. 3rd.com Domain level is Windows 2000 Mixed and the Forest is Windows 2000.

The Dev sharepoint server is located in 3rd.Com domain and the consultant is trying to import Corp.com users by pointing the user profile connection to Corp.com active directory. Needless to say this will fail because there is a one way trust in place so 3rd.com users are allowed to read Corp.Com active directory. Not to mention there are no firewall ports open for this anyway. My questions are...

How can we securely allow this sharepoint server to import in 3rd.com to import users from Corp.com?

Ideally we would like to use a service account from Corp.com to import the accounts. We would also like to either

(A) encrypt the sharepoint servers communication to our Corp.com active directory. because there are Two firewalls between the trust ports would be specifically opened from Sharepoint server <-> Corp.com DC

(b) some how use the existing trust to facilitate this procedures. no additional ports opened on the firewalls.

Any ass

Adding controls dynamically

  

Hi All,
I am creating a questionnaire in a gridview. The questions, answer options and answer control are under CMS. So I am building the questionnaire 'on the fly' adding controls to the page dynamically.

In Page_Load during !Page.IsPostback I bind the question text to the gridview then have another method that iterates through the gridview rows, and adds the controls to a cell eg.gvr.Cells[1].Controls.Add(rbl); The page renders correctly - I see all questions, answers and answer control eg, DropDownList, RadioButtonList, TextBox etc.

The problem is when I try to save the selected options, FindControl cannot find the controls. Even though when I view source I can see all ctrls and ids. I've seen a lot of posts about this issue and CreateChildControl, EnsureChildControl seem to be the route to take. But I don't unserstand how to use them. Can anyone point me to a good example?

And if anyone can explain why it is not working. The page 'looks' to be rendering correctly. Why then are the controls not being found on the postback? Are the controls not being added to the ViewState?

Thanks,
Sinead


Adding controls to a form dynamically

  

How to add checkboxes at a particular positon in a application dynamically.

That is ,I want to add checkboxs depending on the no of items in a collection and i even want to name it.How can i do it?

Can i get any sample code for it?


Tab Control - load user controls in tab dynamically when tab is selected

  

I have searched the forum and I cant seem to find the answer to my question, although I have tried some of the hints I have found with no luck....

Can someone show me a working sample (with source code) of a page with a TabContainer and several tabs, with each tab having a user control, but the controls are not added/initialized/shown until the appropriate tab is shown/clicked?

Something like this forum's "Write a New Post" page, where the tabs load after I click on them, and an animated picture displays to show that its loading.

The solution needs to add user controls to the page, not just html into a dynamic populate extender.

I have one user control per tab, and is linked (ala master-child relationship) to the page using a property. My user controls perform long-running web service queries, and I dont want to waste database/computing resources loading content into a tab that the user will never look at.   Right now, all tabs load their content when the page loads, even though the first tab is only shown.

 
As mentioned above, sample code for the page (.aspx and .cs) and the user control (.ascx and .cs) would really help.

 
Thanks!
 


Enable/Disable controls dynamically based on User settings

  

I need an elegant way to enable/disable controls in my WPF application at run time using an external settings file(xml file)

I know this can be done using binding with Visibility/ IsEnabled property for all the controls, but how will i do change that in run time.

I also want to know whether combining the Settings.settings file and use bindings is the way to go.

There is documentation for VS2005 but not for VS2008 related to Settings.settings file approach.

I need recommendation for this type of features in WPF apps

Any help will be highly appreciated.

 

thanks

Sakti


Dynamically loading different numbers of user controls

  

The web page I am trying to (slowly) build should allow users to add whichever user controls they want on their page, and order them whichever way they like.  This is saved in a database.

So each user could have a different number of controls on the page.

I want to load these web user controls dynamically - I am hoping someone could help me edit my code to do this, or at least point me in the right direction.

This is the design code, at the minute the user controls are fixed and are not loaded dynamically.  They user controls are stored in 'blocks' which look like widgets on the page and can be dragged about to different columns.  For each user the layout is stored in the DB i.e. which blocks are in column 1 and which blocks in column 2 etc. 

How could I change this so that it can create a 'block' div for each user control returned from the database and put the user control in that block and in the right column?

 

				<div class="portal-column" id="portal-column-block-list" style="display: none;">
					<div class="block" id="block-1">
						<h1 class="draghandle">Block 1</h1>
						<p><uc1:wuc01 ID="wuc011" runa

Dynamically Create Controls in ASP.NET by Using Visual C# .NET

  
This article demonstrates how to dynamically create a control for an .aspx page. The sample project does the following:
Creates two TextBox controls.
Verifies that the contents (TextBox.text) and the attributes of the TextBox are saved across posts to the server.
Illustrates handling events that are posted by a dynamically-created control

Dynamically Create Controls in ASP.NET with Visual Basic .NET

  
This step-by-step article describes how to dynamically create controls for an ASPX Web page.

The sample project does the following:
It creates two TextBox controls.
It verifies that the TextBox contents (TextBox.text) and attributes are saved across posts to the server.
It describes how events that are posted by a dynamically created control are handled.

dynamically adding sql server columns based on number of files in fileuploader

  

I want to create a new table to sql database at runtime.  The column names would be "Name", "Date", "Event".  I would also like to have one more column name "Image" but the problem is that since the amount of images will vary, I want the application to count the amount of files in the Multiple fileuploader and then add a image column to the table for the respected amount of files. 

For example if i am uploading 3 files in the multiple fileuploader, the names should be "Name", "Date", "Event", "Image1", "image2", Image3"

I also would like that table name to be name dynamically from the textbox Name when the user enters the information.

 

I have the following code to make a new table, but I dont know how to name the fields at runtime like previously asked please help!!!

 

Dim objConn As New SqlConnection("Server=<servername>;uid=<userid>;pwd=<password>;database=master")

objConn.Open()

UI Datepicker and web user controls

  

Hi,

I have developed an application using the Master-Detail pattern described in this Matt Berseth article.

The only difference between Matt's article and me is that I am using a FormView object in place of a DetailsView.

Everything works fine except that the formview object, in my case it's inside a user control and I can't figure out how to use the jquery datepicker UI plugin.

I have tried to put the script block for the datepicker either in the aspx page as well as inside the user control but in both cases the calendar does not come up when the related textbox get the focus.

Any suggestion on how to work with the datepicker inside an ascx?

thanks in advance!



Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend