Dynamically Created TextBox Doesn't Hold the .Text Property

3 posts, 0 answers
  1. Mike Curtis
    Mike Curtis avatar
    6 posts
    Member since:
    Apr 2006

    Posted 12 May 2009 Link to this post

    I have a form I've created to map data from Excel into our SQL Server-based system.  The basic idea is that a user picks the Excel file to upload, then "maps" the data by selecting the database field then the corresponding Excel column.  Once the user has "mapped" a file, they can save that "mapping" for future use.

    The data on the mapping screen consists of two columns - one an asp:Panel full of dynamically created RadTextBoxes representing the fields in the database (created from the DBSchema) and the other being a GridView of the "column headers" and the first row of data from the Excel file.  From there it's all point and click to map the data - Click on a database field then click on the Excel column. Javascript is used to populate the RadTextBox with the column information and to "remove" the row from the Excel GridView (so a column can only be mapped once).

    When the user "saves" a mapping, the dynamically created RadTextBoxes are walked and rows are created in SQL Server using the name of the RadTextBox and part of the Text property.

    All this works fine.

    The problem I have is when the user tries to "load a mapping" that has previously been saved.  Using the routine that creates the list of RadTextBoxes, I populate the Text property with data from the DB (and set some CSS wrapping the "row").  This is where my problem lies.  I set the Text property, but the value is empty when the page is rendered.  I can set breakpoints in the code and "see" that the property is set to the proper value, but it still displays empty.

    Futhermore - I can set the EmptyMessage property to the same value I'm attempting to place in the Text property and have that display. So something I'm doing is stomping on the Text property, but I just don't see it.  I've stepped line-by-line through the code and the values "hold" but just don't display - unless I take a long time stepping through the code, then it works .....

    I'm not quite sure what's going on with this since I can get this to work by itself, just not in conjunction with the rest of the page.

    I'm using RadControls for ASPNET AJAX Q1 2009

    Here's the code for the function that creates the RadTextBoxes.  On a page by itself it works fine and with ASP:TextBox controls it works fine.  I know this probably isn't enough to go on, but there does seem to be a case when a dynamically created RadTextBox doesn't "hold" the .Text property :)

    protected void FillFieldList(MappingType mtType, Guid? nguidFieldMappingID)  
    {  
        DataTable dtLayout = Property.GetDBSchema();  
        RadTextBox rtxtNewTextBox;  
        FieldMappingItem fmiMappings = new FieldMappingItem();  
        StringBuilder sbControl;  
        string strMappedName = "";  
        bool bolMappedFound = false;  
     
        if ((mtType == MappingType.ReloadMapping) || (mtType == MappingType.LoadSavedMapping))  
        {  
            fmiMappings = new FieldMappingItem(nguidFieldMappingID);  
        }  
     
        foreach (DataRow drData in dtLayout.Rows)  
        {  
            if ((drData["DataTypeName"].ToString() != "uniqueidentifier") && (drData["ColumnName"].ToString() != "Created"))  
            {  
                strMappedName = string.Empty;  
                sbControl = new StringBuilder();  
                sbControl.Append("<div id=\"div");
                sbControl.Append(drData["ColumnName"].ToString());
                sbControl.Append("\" onclick=\"SelectRow('div");
                sbControl.Append(drData["ColumnName"].ToString());
                sbControl.Append("');\"");  
     
                foreach (FieldMappingDetailItem fmdiDetails in fmiMappings.Details)  
                {  
                    if (fmdiDetails.FieldName == drData["ColumnName"].ToString())  
                    {  
                        bolMappedFound = true;  
                        sbControl.Append(" class=\"MapFieldMapped\">");  
                        strMappedName = fmdiDetails.MappedName;  
                        break;  
                    }  
                }  
     
                if (bolMappedFound)  
                {  
                    bolMappedFound = false;  
                }  
                else 
                {  
                    sbControl.Append(">");  
                }  
     
                this.pnlFields.Controls.Add(new LiteralControl(sbControl.ToString()));  
     
                rtxtNewTextBox = new RadTextBox();  
                rtxtNewTextBox.ID = "rtxt" + drData["ColumnName"].ToString();  
                rtxtNewTextBox.CssClass = "FormFieldMapping";  
                rtxtNewTextBox.Label = drData["ColumnName"].ToString();  
                rtxtNewTextBox.LabelCssClass = "FormLabel";  
                rtxtNewTextBox.EmptyMessage = strMappedName;  
                rtxtNewTextBox.Text = strMappedName;  
                this.pnlFields.Controls.Add(rtxtNewTextBox);  
                  
                sbControl = new StringBuilder();  
                sbControl.Append("<input type=\"hidden\" id=\"hdn");
                sbControl.Append(drData["ColumnName"].ToString());
                sbControl.Append("\" value=\"");  
                sbControl.Append(rtxtNewTextBox.ClientID);  
                sbControl.Append("\" />");  
                this.pnlFields.Controls.Add(new LiteralControl(sbControl.ToString()));  
                this.pnlFields.Controls.Add(new LiteralControl("</div>"));  
            }  
        }  
    }  
     
  2. Mike Curtis
    Mike Curtis avatar
    6 posts
    Member since:
    Apr 2006

    Posted 12 May 2009 Link to this post

    Moving this from Page_Load to Page_PreRender solved my issues.

    Thanks anyways :)
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ricardo
    Ricardo avatar
    1 posts
    Member since:
    Mar 2012

    Posted 29 Mar 2012 Link to this post

    I spent my entire morning trying to solve this issue.... thank you! worked like a charm!
Back to Top