[CLOSED] How To Update Value of Dynamically Created Controls (With Dynamic ID's).

Page 1 of 3 123 LastLast
  1. #1

    [CLOSED] How To Update Value of Dynamically Created Controls (With Dynamic ID's).

    In my scenario one TreeNode Click (Click1) event is creating some dynamic controls like TextField, ComboBox, NumberField etc. with values in it (Fetching From Database).
    And Second Direct Event(UpdateEvent) is Updating Data in it (by passing Some SQL queries.)
    Problem is that i Could not update it, as i could not retain ID of the Controls on Update Event. ID becomes null when it comes in Update Region.
    please Help it.....!


    aspx file
    <ext:Panel ID="pnlOuterPropControls" runat="server" Width="620" Height="530">
                                  <Items>
                                      <ext:Panel ID="PnlPropControls" runat="server" Width="500" Height="530" PaddingSpec="20px 0px 0px 30px" AutoDataBind="true"
                                          Border="false">
                                          <Items>
                                          </Items>
                                          <Buttons>
                                              <ext:Button ID="BtnUpdateProp" runat="server" Text="Update !" Width="100" OnDirectClick="BtnUpdateProp_Click"
                                                  Hidden="true">
                                              </ext:Button>
                                              
                                          </Buttons>
                                      </ext:Panel>
                                  </Items>
                              </ext:Panel>
    code behind
    public void Click1(object sender, DirectEventArgs e)
            {
                BtnUpdateProp.Show();
             
                PnlPropControls.RemoveAll();
                string TfNewParntHierName = e.ExtraParams["CmptMstrpk1"].ToString();
                Session["sessionTfNewParntHierName"] = TfNewParntHierName;
                string shrtdesc = fn.Selectsinglevalues("select accountShortDesc from tc_AccountCodes where pk_AccountCode = '" + TfNewParntHierName + "' ");
                
                Session["shrtdesc"] = shrtdesc;
                DataSet dsPg = fn.Selectdata("select * from dbo.tc_configuration where configPropCatgSub = '" + shrtdesc + "' order by configpropsrno asc");
                for (int i = 0; i < dsPg.Tables[0].Rows.Count; i++)
                {
                    string Controlpk = dsPg.Tables[0].Rows[i]["pk_configuration"].ToString();
                    string ControlType = dsPg.Tables[0].Rows[i]["configPropType"].ToString();
                    string ControlDataType = dsPg.Tables[0].Rows[i]["configPropDataType"].ToString();
                    string ControlItem = dsPg.Tables[0].Rows[i]["configPropItem"].ToString();
                     
                    if (ControlType == "Numeric")
                    {
                        NumberField nFNumericData = new NumberField();
                        nFNumericData.ID = "nFNumericData_" + i.ToString();
                       
                        nFNumericData.MaxValue = 100;
                        nFNumericData.MinValue = 0;
                        nFNumericData.Text = fn.Selectsinglevalues("select configPropValue from tc_configuration where pk_configuration = '" + Controlpk + "'  ");
                        nFNumericData.FieldLabel = fn.Selectsinglevalues("select configPropItem from tc_configuration where pk_configuration = '" + Controlpk + "' ");
                        PnlPropControls.Items.Add(nFNumericData);
                       nFNumericData.Render();
                      
                    }
                    
              
                     
                         
                     
                }
            }
     
            public void BtnUpdateProp_Click(object sender, DirectEventArgs e)
            {
                DataSet ds = fn.Selectdata("select * from dbo.tc_configuration where configPropCatgSub = '" + Session["shrtdesc"] + "' order by configpropsrno asc");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string Controlpk = ds.Tables[0].Rows[i]["pk_configuration"].ToString();
                    string ControlType = ds.Tables[0].Rows[i]["configPropType"].ToString();
                    string ControlDataType = ds.Tables[0].Rows[i]["configPropDataType"].ToString();
                    string ControlItem = ds.Tables[0].Rows[i]["configPropItem"].ToString();
                    TextField tfDescription = (TextField)PnlPropControls.FindControl("tfDescription");
                    NumberField nFNumericData = (NumberField)PnlPropControls.FindControl("nFNumericData");
     
                  
                    TextBox tbnnn = (TextBox)PnlPropControls.FindControl("tbnnn");
     
                    if (ControlType == "Numeric") // Checking condition "Values Stored in DB"
                    {
                        fn.updatedata(" update tc_configuration set configPropValue = '" + nFNumericData.Value + "' where pk_configuration = '" + Controlpk + "'  ");
                    }
                  
                    
                    
                     
     
                }
     
         
     
     
            }
    Last edited by Daniil; Apr 24, 2013 at 6:29 AM. Reason: [CLOSED]
  2. #2
    Hi @Tonic,

    If you create/render a control during one request (a DirectEvent), it doesn't persists automatically during another request (a DirectEvent). It is why you are getting nulls.

    To update fields I would try the following.
    X.GetCmp<TextField>("TextField1").Text = "new text";
  3. #3
    thanks for reply,

    but sir problem is still the same, i am unable to use it..
    can u please tell me where to place the code line you wrote.

    And one more thing, ID of Controls are generating Automatilcally for about 100's of entries for different Controls (Depending upon DB)

    i am using this code line to get values of number field and use it in update query
    NumberField nFNumericData = (NumberField)PnlPropControls.FindControl("nFNumericData");
    this is my update query
     if (ControlType == "Numeric") // Checking condition "Values Stored in DB"
                    {
                        fn.updatedata(" update tc_configuration set configPropValue = '" + nFNumericData.Value + "' where pk_configuration = '" + Controlpk + "'  ");
                    }
  4. #4
    Please take a look at the example.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void RenderTextField(object sender, DirectEventArgs e)
        {
            TextField tf = new TextField();
            tf.ID = "TextField1";
            tf.Text = "initial text";
    
            tf.AddTo(this.Form);
        }
    
        protected void UpdateTextField(object sender, DirectEventArgs e)
        {
            X.GetCmp<TextField>("TextField1").Text = "new text";
        }
    </script>
    
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />        
    
            <ext:Button runat="server" Text="Render TextField" OnDirectClick="RenderTextField" />
    
            <ext:Button runat="server" Text="Update TextField" OnDirectClick="UpdateTextField" />
        </form>
    </body>
    </html>
  5. #5

    X.GetCmp<TextField>("TextField1").Text = "new text";

    thanks for your Consideration...!

    but it is not working..in my code .

    What Exactly i need is nFNumericData.Text which is needed in update query, but unfortunately it is comming null every time.

    and also as you have hardcoded ID of textfield, but in my case it changes depending on DB , like: textfield1,combobox2,textfield3,numberfield4,textf ield5 in a go
    please refer the code i gave....today


    update tc_configuration set configPropValue = '" + nFNumericData.Text+ "' where pk_configuration = '" + Controlpk + "' ");
  6. #6
    Maybe, I misunderstand something.

    Do you need to submit the field's values from client (browser) to server (code behind), then push those values to a database, correct?
  7. #7

    Reply...

    exactly sir...
  8. #8
    OK. To have access to the update text you should know a control's ID.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        protected void RenderTextField(object sender, DirectEventArgs e)
        {
            TextField tf = new TextField();
            tf.ID = "TextField1";
            tf.Text = "initial text";
     
            tf.AddTo(this.Form);
        }
     
        protected void Get(object sender, DirectEventArgs e)
        {
            X.Msg.Alert("Get", X.GetCmp<TextField>("TextField1").Text).Show();
        }
    </script>
     
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />        
     
            <ext:Button runat="server" Text="Render TextField" OnDirectClick="RenderTextField" />
     
            <ext:Button runat="server" Text="Get TextField's Text" OnDirectClick="Get" />
        </form>
    </body>
    </html>
  9. #9

    thanks Sir...

    thanks a lot... the code you suggested worked.!
    the Problem is Resolved now..... :-)
    i was using
      PnlPropControls.Items.Add(dfMaxDate);
    instead of
         dfMaxDate.AddTo(this.PnlPropControls);

    You may now Close the thread
  10. #10
    You can put a control to an Items collection instead of calling the AddTo method, but you also have to call its Render method.

    Example
    <%@ Page Language="C#" %>
      
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
      
    <script runat="server">
        protected void RenderTextField(object sender, DirectEventArgs e)
        {
            TextField tf = new TextField();
            tf.ID = "TextField1";
            tf.Text = "initial text";
    
            this.Container1.Items.Add(tf);
            tf.Render();
        }
      
        protected void Get(object sender, DirectEventArgs e)
        {
            X.Msg.Alert("Get", X.GetCmp<TextField>("TextField1").Text).Show();
        }
    </script>
      
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />  
            
            <ext:Container 
                ID="Container1" 
                runat="server" 
                Width="200" 
                Height="100" />
      
            <ext:Button runat="server" Text="Render TextField" OnDirectClick="RenderTextField" />
      
            <ext:Button runat="server" Text="Get TextField's Text" OnDirectClick="Get" />
        </form>
    </body>
    </html>
Page 1 of 3 123 LastLast

Similar Threads

  1. Replies: 0
    Last Post: Apr 22, 2013, 1:20 PM
  2. saving dynamically-created controls' values
    By Skizzot223 in forum 1.x Help
    Replies: 1
    Last Post: Apr 16, 2012, 12:54 PM
  3. [CLOSED] How to clean up dynamically created controls?
    By jchau in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 23, 2011, 9:51 AM
  4. [CLOSED] Unable to access dynamically created controls
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 07, 2011, 5:49 AM
  5. Dynamically created controls cookbooks
    By arodier in forum 1.x Help
    Replies: 15
    Last Post: May 07, 2010, 7:12 PM

Posting Permissions