[CLOSED] Extra Parameters in Textfields

  1. #1

    [CLOSED] Extra Parameters in Textfields

    Hi,

    I'm trying to create a dynamic form, which is working fine. The issue I'm having is correlating textbox.Text to the primary key it should be associated with. Is there a way to add a parameter to the textboxes during their creation so that it can have a primary key in it (besides generating ID's based on primary key)? Code below to illustrate the issue:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm11.aspx.cs" Inherits="WebApplication1.WebForm11" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
        public class SampleData
        {
            public int Id { get; set; }
            public string Description { get; set; }
            public string Value { get; set; }
        }
        List<SampleData> GetData()
        {
            var result = new List<SampleData>();
            result.Add(new SampleData { Id = 1, Description = "Sample Field#1", Value = "sf1" });
            result.Add(new SampleData { Id = 2, Description = "Sample Field#2", Value = "sf2" });
            result.Add(new SampleData { Id = 3, Description = "Sample Field#3", Value = "sf3" });
            result.Add(new SampleData { Id = 4, Description = "Sample Field#4", Value = "sf4" });
            result.Add(new SampleData { Id = 5, Description = "Sample Field#5", Value = "sf5" });
            return result;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            CreateFields();
        }
        protected void CreateFields()
        {
            List<SampleData> d = GetData();
            foreach (var x in d)
            {
                var tf = new Ext.Net.TextField();
                tf.Text = x.Value;
                tf.FieldLabel = x.Description;
                //Could use line below to mimick extra param requirement
                tf.ID = "tf" + x.Id.ToString();
                Panel1.Add(tf);
            }
        }
        protected void click(object sender, DirectEventArgs e)
        {
            foreach (Ext.Net.TextField x in Panel1.Items)
            {
                var newText = x.Text;
                //var Id = x.ExtraParams["id"];
            }
        }
    </script>
    <!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>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server">
        </ext:ResourceManager>
        <form id="form1" runat="server">
        <div>
            <ext:Panel ID="Panel2" runat="server" Height="350">
                <Items>
                    <ext:Panel ID="Panel1" runat="server" Height="300" Title="Title" />
                    <ext:Button ID="Button1" runat="server" Text="Submit">
                        <DirectEvents>
                            <Click OnEvent="click" />
                        </DirectEvents>
                    </ext:Button>
                </Items>
            </ext:Panel>
        </div>
        </form>
    </body>
    </html>
    Last edited by Daniil; Jul 06, 2012 at 3:43 PM. Reason: [CLOSED]
  2. #2
    Hi,

    I am not sure that I understand the requirement well.

    I guess you could use the TextField Tag property for any additional data about the control.

    Create the control:
    tf.ID = "tf" + x.Id.ToString();
    tf.Tag = x.Id;
    Access the Tag within the DirectEvent handler:
    foreach (Ext.Net.TextField x in Panel1.Items)
    {
        var newText = x.Text;
        var id = x.Tag;
    }
  3. #3
    I don't see any tag property http://docs.ext.net/frlrfExtNetTextF...opertiesToggle , am I looking in the wrong place?

    I have two parameters that I'd like to get back from a text box, which are a composite primary key for what's in the textbox.

    Say, you have a database table
    if NOT EXISTS ( select 1 from INFORMATION_SCHEMA.tables
    where TABLE_SCHEMA='dbo' and TABLE_NAME='test')
    BEGIN
    CREATE TABLE dbo.test
    	(
    	key1 int NOT NULL,
    	key2 int NOT NULL,
    	v varchar(50) NULL
    	)  
    ALTER TABLE dbo.test ADD CONSTRAINT
    	PK_test PRIMARY KEY CLUSTERED 
    	(
    	key1,
    	key2
    	)
    insert dbo.test (key1, key2, v)
    values (1,1,'a'),(1,2,'b'),(2,1,'c'), (2,2,'d')
    END
    I need to be able to create textboxes dynamically, pass key1 and key2 to them as some extra parameters, and then in DirectMethod be able to reference key1 and key2.

    Did this clarify the question?
  4. #4
    I think the docs has just not been updated.

    Please look at the example how you can use the Tag property.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        class Keys
        {
            public string Key1 { get; set; }
            public string Key2 { get; set; }
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            TextField tf = new TextField();
            tf.ID = "TextField1";
            tf.Tag = new Keys()
            {
                Key1 = "some key 1",
                Key2 = "some key 2"
            };
    
            this.Form.Controls.Add(tf);
        }
    
        protected void GetKeys(object sender, DirectEventArgs e)
        {
            TextField tf = this.FindControl("TextField1") as TextField;
            Keys keys = tf.Tag as Keys; 
            
            X.Msg.Alert("Keys", string.Format("key1: {0}, key2: {1}", keys.Key1, keys.Key2)).Show();
        }
    </script>
    
    <!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>Ext.NET Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:Button runat="server" Text="Get TextFields keys" OnDirectClick="GetKeys" />
        </form>
    </body>
    </html>
  5. #5
    thanks. Let me try that and I'll report back next week.
  6. #6
    I don't see any tag property on textfields. Is it because I'm using v1.2.0.21945?
  7. #7
    Hi,

    Yes, it has appeared after v1.2.

    I would recommend to upgrade to v1.4 or from SVN.

    If it's not an option, you could implement your own custom control extending the TextField with any required properties.

Similar Threads

  1. Replies: 4
    Last Post: Apr 21, 2011, 6:04 AM
  2. send extra parameters on blur event of textfield editor inside gridpanel
    By aditya.murthy88@gmail.com in forum 1.x Help
    Replies: 2
    Last Post: Dec 11, 2010, 12:04 PM
  3. Listener Fn - How can I pass extra parameters?
    By lionelhutz in forum 1.x Help
    Replies: 0
    Last Post: Dec 10, 2009, 5:25 PM
  4. Extra parameters Ajax Method from a Text Field
    By davromu in forum 1.x Help
    Replies: 4
    Last Post: Jun 17, 2009, 3:27 PM
  5. Replies: 2
    Last Post: Jan 27, 2009, 3:56 PM

Posting Permissions