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

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Alignment for Dyanamically created control.

Posted By:      Posted Date: September 20, 2010    Points: 0   Category :ASP.Net


I am creating some label and textbox dynamically in a Panel. I am not able to do alingment. I need to allign all textboxes. Below is code.

 private void LoadControls(string strGridId, DateTime dtGridDate)
            pnlSectorGrid.Visible = true;
            DataSet ds = GetSectorialGridData(strGridId, dtGridDate);
            for (int Index = 0; Index < ds.Tables[0].Rows.Count - 1; Index++)

                Label lblSectorName = new Label();
                lblSectorName.Text = ds.Tables[0].Rows[Index]["tsu_SubSectorName"].ToString();
                lblSectorName.Font.Size = 10;
                Label space = new Label();
                space.Text = "            "; 
                TextBox txtAlloc = new TextBox();
                txtAlloc.Text = ds.Tables[0].Rows[Index]["Alloc"].ToString();
                txtAlloc.Font.Size = 10;
                txtAlloc.Width = 90;              
                pnlSectorGrid.Controls.Add(new WebControl(HtmlTextWriterTag.Br));
                if (ds.Tables[0].Rows[Index]["tsu_SubSectorID"].ToS

View Complete Post

More Related Resource Links

Get content of programatically created control before postback

Hi.I have quite a problem here, and hope you can help :)I´ll try to describe the problem in steps, as this might be the easiest to understand:1. Page_Load is called when the page is requested, and calls a BuildTable() method2. The BuildTable method creates a table which contains several textboxes3. the user types some text in these textboxes4. The userthen  changes an item in a Dropdownlist on the page which is intended to change some other content on the page5. Page_Load is called, and afterwards the DropDownListBookingType_SelectedIndexChanged(object sender,EventArgs e) method are called, and the content is changed6. The text the user typed in the programmatically created textbox controls are lost!Now how do I remain this text information? If just the SelectedIndex_changed method was called first, I could save it in session.. But as far as I can tell, all data on the page are discarded when you create a partial postback :(What to do?Thanks alot for your time!

loadviestate of control created on the load() event

Why if I create a label on the load() event its properties are restored after a postback, even though it doesn't pass through the loadviestate stage? Example:Partial Class Default2 Inherits System.Web.UI.Page Protected Overrides Sub LoadViewState(ByVal savedState As Object) MyBase.LoadViewState(savedState) End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim lb As New Label Me.Controls.Add(lb) If Not Page.IsPostBack Then lb.Text = "xxxx" End If End Sub End Class <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>title</title> </head> <body> <form id="form1" runat="server"> <asp:Button ID="Button1" runat="server" Text="Button" /> </form> </body> </html>   And why everybody advice to create controls in the overrides of the method LoadViewState(), if it's ok also in the load() event

dynamically created button control click event not firing first time?

HI im creating a button control in page int and im assing a click event for the button control. here the click event is not firing for the first time.can anyone help me with this? here is my code. Button btn = new Button(); btn.ID = "btn"; btn.Click += new EventHandler(btn_Click); Panel1.Controls.Add(btn); Panel1.Controls.Add(new LiteralControl(""));

I cant use my created class in my web control

So this is the big picture:The picture should explained my situation. And I cant go to defination inside a class that call another class's method tooPls help me :(

Find a form control that is created after postback

HiI have a drop down list (created during form design) with auto postback enabled. And I use AJAX to prevent 'visible postback'. When a user choose an item from the drop down list, the system will then perform a postback and created a set of form control's such as label, drop down list and text box for entry.Then, I will have a button (created during form design), and when I click on the button, i want to find for the form control that are created after the post back, but I cant find them!I wonder if those form controls are render to the web form?? But I have no problem finding the drop down list that is created during design time.Anyway I can find those form controls?Thank You.

I created a new control and im drawing some lines and points inside but the form1 designer throw me


This is the code of the control:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace My_Diet_Control
    public partial class My_Diet_Graph_Control : UserControl
        int x_axis_lenght;
        int y_axis_lenght;
        int marginLeft;
        int marginRight;
        int marginBottom;
        int marginTop;
        My_Diet_Graph_Control myControl1;
        Diet_Data myData;
        public My_Diet_Graph_Control()

        private void My_Diet_Graph_Control_Load(object sender, EventArgs e)

How to use Login Control in already created Web Site Project ?



actually i have already created my web site project.Now i want to use login control in my project.So can you please guide me how i can use it in my existing project? 

Error with dyanamically Created AjaxControlToolkit TabPanel


I am getting an error in my application in  AJAXControlToolkit.ScriptControlBase.System.Web.UI.IPostBackDataHandler.LoadPostData. 

I am adding and removing tab panels based on user input data.  Sometimes the app creates 5 to 10 pannels and sometimes only 1 or 2 depending on the user input parameter.  The error occurs when the user input parameter dictates that 10 panels be created.  When the user then changes the input parameter to a selection that only requires 1 panel the error occurs and the error message refers to a parameter name :index with the specified argument out of range  It appears that is is still looking for the 10 panels created in the previous user selection.  The error message is in the Disassembly of the AJAXControlToolkit.  I thought maybe was linked to enableviewstate but I set this to false for the tabpanel and tabcontainer yet still get the error.



control not working when created on new thread



I recently read this article and implemented -


I changed my control (dev express pivot grid) to be created on a secondary background.

The control is loading and displaying faster (great) but now if I try t omove the scrollbar etc nothing happens. The control has stopped responding to events.

Can anyone tell me how to resolve this issue. I'm not exactly sure where to start looking.

I need a way of getting the mouse drag events across to my control on the secondary thread.


C# following exception while reflection of dynamically created control.


ControlType = "System.Windows.Forms.WindowsFormsApplication1." + "PictureBox1"; System.Reflection.Assembly asm; asm = typeof(Form).Assembly; ControlObject = (System.Windows.Forms.Control)asm.CreateInstance(ControlType); ControlObject.Name = ControlName; The next code generated following exception for me: ControlObject.Name = ControlName;

NullReferenceException was unhandled Object reference not set to an instance of an object.

invoke or begininvoke cannot be called on a control until the window handle has been created


Hello , Our application use the SQL 2008 R2 express edition 32/64 bit .

Now we have a new upgrade for our Application but we need to update the Existing SQL 2008 R2 express to a SQL 2008 R2 advanced services

to install the add-in Full Text Search.

When we do a upgrade during the setup , maintenance / upgrade , First we get a completed messagebox , after 1 min we get

the following error : invoke or begininvoke cannot be called on a control until the window handle has been created.

On the internet / microsoft there are patches for this known issue but not for the R2 version only for the SQL 2008 Express .

What can I do to update my SQL 2008 R2 express edition to a edvanced edition.

Anybody ?

Thanks , Yours Sincerely

Control.Invoke must be used to interact with controls created on a separate thread.


I am making a stock taking application in a smart device projec tin Visual Studio 2010. What i want to do is create a thread for when i want to update the database(csv file) and use a status control to show the user what is happening ("connecting", "saved", "error") etc.


However when i try to call a function from within my save method whcih is running on a thread i get a Control.Invoke must be used to interact with controls created on a separate thread error at runtime.

    private void btnUpdateStock_Click(object sender, EventArgs e)
      if (this.txtStock.ReadOnly == false && notSaving)
        Product p = dataManager.getCurrentProduct();
        p.unitsInStock = Int32.Parse(this.txtStock.Text);

        Thread saveThread = new Thread(new ThreadStart(saveItems));


    public void saveItems()

Adding Dynamic Rows in ASP.NET GridView Control with TextBoxes and with Delete functionality

In my previous examples, I have demonstrated on how to add dynamic rows in GridView control with TextBoxes and how to save the values into the database. Now, seems that most of the developers are asking if how to add a delete functionality with it. So in this example, I'm going to show on how to delete a certain row in the dynamic GridView with TextBoxes.

Accessing the different controls inside a GridView control

how we can access a particular control which resides inside a GridView control. In this article I will show you how you can access different controls inside a GridView control. We will see how we can access a TextBox control, a DropDownList control and a ListBox control. If you are working with ASP.NET 1.X then you might want to check out my article Accessing Different Controls Inside a DataGrid.

In-Depth look at the GridView Control

In the last article we looked at few of the new controls available in Asp.net 2.0. We also talked about Grid View Control which has replaced the Asp.net 1.1 DataGrid control for good. In this article we will examine more features of the Grid View control. In this article we will see some of the common operations that can be performed using the GridView control. Apart from these operations there are many more functions that can be performed on the control and which we will see in the later articles

ASP.NET repeater control - databind with style

even used the inline editing features, which I at the time thought was the coolest way possible to write ASP.NET code ( I managed to write code to hide all other rows and only show the current one - the row being edited). With a nice looking EditTemplate it looked indeed very slick but it really turned into giant and hard to manage code behind files.

Creating Paging for a Repeater Control

A common question is "How do I implement paging within a Repeater?" Although the beauty of the Repeater control is its flexibility, you're on your own for building most functions. ASP.NET 2.0 has included some new controls that provide paging, as does the DataGrid in ASP.NET 1.1. However, this tip shows you how to roll your own paging for a simple data viewer.
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