Latest developer linksBookmark and Share
 
HomeThis WeekTop MonthTop AlltimeSearchRegisterFAQ
  
 
Submit Your Link
Please login to submit your Link
 

Create more than 1 set of controls in runtime.

Posted: Dec/14/2010   By: nikhil   Points:15   Category: .NET  - ASP.Net    Views:119   Vote Up (0)   Vote Down (0)    

I've figured out how to create the controls in the format I want, but now I am confused as to how create more than one set of them. I set everything to new and increment the names of each control, but it's only updating the one set. Here is my code:

  intPnlCounter += CInt(ViewState("intPgCount"))
        
        'Table
        'PlaceHolder1.Controls.Add(New LiteralControl(" <table style=""height: 27px""><tr><td colspan=""2""> </td><td colspan=""2"">"))
        PlaceHolder1.Controls.Add(New LiteralControl("<table style=""height: 27px"">"))

        'Component Header
        Dim lblHeader As Label = New Label
        lblHeader.Text = "Additional Component Item: " & intPnlCounter
        lblHeader.ID = "lblHeader" & intPnlCounter
        lblHeader.Font.Bold = True
        lblHeader.Font.Underline = True
        lblHeader.Font.Name = "Trebuchet MS"
        PlaceHolder1.Controls.Add(lblHeader)
        PlaceHolder1.Controls.Add(New LiteralControl("<tr><td colspan=""2""> </td><td colspan=""2"">"))

        'Item Label
        Dim lblItem As Label = New Label
        lblItem.Text = "Item:"
        lblItem.ID = "lblItem" & intPnlCounter
        lblItem.Font.Bold = True
        lblItem.Font.Underline = True
        lblItem.Font.Name = "Trebuchet MS"
        'lblItem.Font.Size = Unit.Percentage(10)
        PlaceHolder1.Controls.Add(lblItem)
        PlaceHolder1.Controls.Add(New LiteralControl(" "))
        'Item Textbox
        Dim txtItem As TextBox = New TextBox
        txtItem.ID = "txtItem" & intPnlCounter
        txtItem.Width = Unit.Pixel(306)
        PlaceHolder1.Controls.Add(txtItem)
        PlaceHolder1.Controls.Add(New LiteralControl("</td><td> </td></tr><tr><td class=""style11"">"))

        'NSN Label
        Dim lblNSN As Label = New Label
        lblNSN.Text = "NSN:"
        lblNSN.ID = "lblNSN" & intPnlCounter
        lblNSN.Font.Bold = True
        lblNSN.Font.Underline = True
        lblNSN.Font.Name = "Trebuchet MS"
        lblNSN.Font.Size = 10
        PlaceHolder1.Controls.Add(lblNSN)
        PlaceHolder1.Controls.Add(New LiteralControl(" "))
        'NSN Textbox
        Dim txtNSN As TextBox = New TextBox
        txtNSN.ID = "txtNSN" & intPnlCounter
        PlaceHolder1.Controls.Add(txtNSN)
        PlaceHolder1.Controls.Add(New LiteralControl("</td><td class=""style12"">"))

        'PartNum Label
        Dim lblPartNum As Label = New Label
        lblPartNum.Text = "Part Number:"
        lblPartNum.ID = "lblPartNum" & intPnlCounter
        lblPartNum.Font.Bold = True
        lblPartNum.Font.Underline = True
        lblPartNum.Font.Name = "Trebuchet MS"
        lblPartNum.Font.Size = 10
        PlaceHolder1.Controls.Add(lblPartNum)
        PlaceHolder1.Controls.Add(New LiteralControl(" "))
        'PartNum Textbox
        Dim txtPartNum As TextBox = New TextBox
        txtPartNum.ID = "txtPartNum" & intPnlCounter
        PlaceHolder1.Controls.Add(txtPartNum)
        PlaceHolder1.Controls.Add(New LiteralControl("</td><td colspan=""2"">"))

        'SerialNum Label
        Dim lblSerialNum As Label = New Label
        lblSerialNum.Text = "Serial Number:"
        lblSerialNum.ID = "lblSerialNum" & intPnlCounter
        lblSerialNum.Font.Bold = True
        lblSerialNum.Font.Underline = True
        lblSerialNum.Font.Name = "Trebuchet MS"
        lblSerialNum.Font.Size = 10
        PlaceHolder1.Controls.Add(lblSerialNum)
        PlaceHolder1.Controls.Add(New LiteralControl(" "))
        'SerialNum Textbox
        Dim txtSerialNum As TextBox = New TextBox
        txtSerialNum.ID = "txtSerialNum" & intPnlCounter
        PlaceHolder1.Controls.Add(txtSerialNum)
        PlaceHolder1.Controls.Add(New LiteralControl("</td><td>"))

        'Hours Label
        Dim lblHours As Label = New Label
        lblHours.Text = "Hours:"
        lblHours.ID = "lblHours" & intPnlCounter
        lblHours.Font.Bold = True
        lblHours.Font.Underline = True
        lblHours.Font.Name = "Trebuchet MS"
        lblHours.Font.Size = 10
        PlaceHolder1.Controls.Add(lblHours)
        PlaceHolder1.Controls.Add(New LiteralControl(" "))
        'Hours Textbox
        Dim txtHours 
                          
                               

View Complete Post


Comments:
Be the first to comment this post.
 
Post Comment
Please login to post your comment
More Related Resources

Creating the CAPTCHA Functionality At Runtime

  
According to wikipedia, CAPTCHA ("Completely Automated Public Turing test to tell Computers and Humans Apart") is a challenge response test which is used to check that if the user is human or not. CAPTCHA is used exclusively in applications where the user input is required. These applications include Blogs, Forums and Portals. In this article I will demonstrate how to create a simple webpage that uses CAPTCHA functionality.

Loading User Controls Dynamically

  
User Controls are great in ASP.NET. They let us divide the page into small sections. You can easily use User Controls on a ASP.NET page by simply dragging and dropping the control from the solution explorer. Sometimes we need to load the User Control dynamically. In this small article we will learn how to load the User Control dynamically.

Changing Style Sheet of Controls Dynamically

  
CSS (Cascading Style Sheets) provides easy maintenance for the look and feel of the website. Sometimes we need to set the style of lot of controls dynamically using style sheet. In this article I will show how you can change the style sheet of the dynamically created label controls.

Create Navigation in asp.net web application

  
Create Navigation in asp.net web application. Create Navigation in asp.net

create a method similar to this

  

In one of our pages we are using this bit of code to check if something is null and passing in a 0 instead. This works great for this page, but this was done by another person and thye are no longer here.. so i'd like to take that idea and create something similar but return a empty string or blank space, the reason is that i have a page where you make a selection from a gridview and onselect that rows data is passed into some textboxes.. well at the moment, if you select a row and one of the columns is blank, the textbox is being populated anyway with this &nbsp; so i would like to make sure that if there is nothing, that the textboxes are left blank.. since there is potential for having alot of textboxes, i would rather create a method that can do the checking instead of doing if condition for each parameter. does that make sense? If so any suggestions would be great. and thanks you

        //CONVERTS NULL VALUES TO ZERO
        protected string valid(OleDbDataReader myreader, int stval)
        {
            object val = myreader[stval];
            if (val != DBNull.Value)
                return val.ToString();
            else
                return Convert.ToString(0);
        }
        //END


 


How can i create Barcode for coupon???

  

 Hi all,

I am creating a web site that provide coupon for it's registered member. I want to set up barcoad for each coupon that the member printed. How can i create barcode and Print them in a html page that is used as my coupon page.

Is anybody can give me solution for that???? Please help me, its argent.

Bye

With regards

Sadequzzaman Monoj

Bangladesh


Using VB, how do I use the For i = 1 to 10 to create a dynamic double variable

  

I have some global variables declared and want to access them in subrorutines using the For statement. 

For example, I want to use the following to place values in the global variables , i.e, dblcell1, dblcell2, dblcell3, etc. 

Dim m As Integer
			For m = 3 To 11
				If e.Row.Cells(m).Text <> " " Then
					dblCell & m = e.row.cells(m).text)
				End If
			Next

I know that I can't use the "dblCell & M".  It is just to show the objective. It is where I get an error.

 

Thanks
 

 


Trying to create a data set that I can reuse

  

Hard to describe be here goes.

Currently I have this in the aspx page

<% = new BuildFormField() { FieldName = "FirstName" }%>

And the simplified object

Class BuildFormField(){

   return GetFieldAttributes("FirstName") //calls a linq query based on the field name to get all the attributes of the field ie size/class and builds the html string.

}

The problem is, I will have many of these and it queries the database every time. What I would like to do is build a general dataset once and query that result set for each field.

I can't figure out where I should setup the initial query. Obviously don't want to put it in the aspx page or the controller and I can't figure out how to create a class that would only get called once that I could use again inside the BuildFormField Class.

Hope that makes sense. Yea, a bit unusual of a way to create form fields, but there is good reasons.

 

Thanks ahead of time.


Microsoft JScript runtime error: Sys.ArgumentException: Value must not be null for Controls and Behaviors. Parameter name: element

  

Hello,

I am facing this error 

Microsoft JScript runtime error: Sys.ArgumentException: Value must not be null for Controls and Behaviors.
Parameter name: element

Microsoft JScript runtime error: Sys.ArgumentException: Value must not be null for Controls and Behaviors.

Parameter name: element

while using Ajaxtoolkit ModelPopupextender with listview, actually I am retriving image from database to the listview in VS 2008. 

Can anyone please help me out of this..


Visual Studio 2010 Upgrade broke all controls in design

  

I have recently upgraded from VS 2008 to VS 2010 and the conversion process completed successfully.  However, when viewing my design view for all aspx pages, any control i had in there is displayed with the message "Error Creating Control - Object Reference not set to instance of an Object".  If i even attempt to create a simple new button or textbox from the toolbox, the control automatically comes back with that error.  However, in runtime, my controls are all displayed and functioning correctly.

I have seen some posts regarding session state and checking that Context is not null in the OnInIt override method, but I am no using any OnInIt override methods in any of my code behinds.  It pretty standard with usually only page loads.

This is creating a tough time developing because it is not using intellisense when i am looking for events and other actions on the controls.  Also, Javascript does not appear to be functioning the same  since it doesnt seem to be using the FindControl method correctly (Probably because the page is building out the control).

This is very frustrating and i've spent two days on this, so any help would be appreciated.

Thanks! 


 
Categories:
.NET
Java
PHP
C/C++/VC++
HTML/XML
SAP
MainFrames
Data Warehousing
Testing
MySQL
SQL Server
Oracle
Javascript/VB Script
Others
Login
 
 
 
 
 Forgot password
 Contact Us   Terms Of use   Share your knowledge