How to dynamically create Barcode Professional controls at runtime in ASP.NET
Technologies used
- Neodynamic Barcode Professional 2.0 for ASP.NET (WebControl)
- Microsoft .NET Framework (any version)
- Microsoft Visual Studio .NET (any version)
You can create barcode controls at runtime. In the following sample we're going to create a simple ASP.NET WebForm that shows this. In the sample, we'll create a barcode control in the Page's Load event as well as we'll create a barcode control as a response to a click event of a Button in the WebForm.
Follow these steps to create a barcode control in the Page�s Load event:
- Open your .NET development tool � such as Visual Studio .NET � and create a new ASP.NET Web Application.
- Drag and Drop a PlaceHolder control onto it. This control will hold the barcode control we're going to create at runtime.
In the Page_Load event procedure write the following code:
Visual Basic .NET
'Create an instance of Barcode Professional
Dim bcp As New BarcodeProfessional
'Set some properties
bcp.Code = "Created at RUNTIME!"
bcp.Symbology = Symbology.Code128
bcp.ForeColor = Color.RoyalBlue
bcp.Font.Bold = True
'Add the Barcode control
PlaceHolder1.Controls.Add(bcp)
Visual C# .NET
//Create an instance of Barcode Professional
BarcodeProfessional bcp = new BarcodeProfessional();
//Set some properties
bcp.Code = "Created at RUNTIME!";
bcp.Symbology = Symbology.Code128;
bcp.ForeColor = Color.RoyalBlue;
bcp.Font.Bold = true;
//Add the Barcode control
PlaceHolder1.Controls.Add(bcp);
That's it. Build the ASP.NET Web Application and run it.
Follow these steps to create a barcode control in a Button's Click event:
- Open your .NET development tool � such as Visual Studio .NET � and create a new ASP.NET Web Application.
- Drag and Drop a Button control and a PlaceHolder control onto it.
In the Page_Load event procedure write the following code:
Visual Basic .NET
'Serve barcode requests
'This call is required when the control is created
'in a PostBack stage
BarcodeProfessional.ProcessBarcodeRequest()
Visual C# .NET
//Serve barcode requests
//This call is required when the control is created
//in a PostBack stage
BarcodeProfessional.ProcessBarcodeRequest();
Finally, write the following code in the Button1_Click event procedure:
Visual Basic .NET
'Create an instance of Barcode Professional
Dim bcp As New BarcodeProfessional
'Set some properties
bcp.Code = "Created at RUNTIME TOO!"
bcp.Symbology = Symbology.Code128
bcp.ForeColor = Color.Red
bcp.Font.Bold = True
'Add the Barcode control
PlaceHolder1.Controls.Add(bcp)
Visual C# .NET
//Create an instance of Barcode Professional
BarcodeProfessional bcp = new BarcodeProfessional();
//Set some properties
bcp.Code = "Created at RUNTIME TOO!";
bcp.Symbology = Symbology.Code128;
bcp.ForeColor = Color.Red;
bcp.Font.Bold = true;
//Add the Barcode control
PlaceHolder1.Controls.Add(bcp);
That's it. Build the ASP.NET Web Application and run it.
If you need more information or assistance, please contact our
.
|