[CLOSED] How to get the control ID after I using "Control2.Render(Control1,RenderMode.AddTo)"?

  1. #1

    [CLOSED] How to get the control ID after I using "Control2.Render(Control1,RenderMode.AddTo)"?

    First you had helped me to resolve the problem:

    http://forums.ext.net/showthread.php?10547-CLOSED-How-to-get-the-control-ID-after-I-using-quot-Control2.Render(Control1-RenderMode.AddTo)-quot

    But when I want to check the control in another Button Event, it was failed again:
    So please help me to check the code , thanks.
    (I want to get the control in another event CheckControl())

    
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx.cs" Inherits="Default6" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!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>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:Panel ID="PanelsCt" runat="server" AutoHeight="true" Title="Panels container">
            <TopBar>
                <ext:Toolbar ID="Toolbar1" runat="server">
                    <Items>
                        <ext:Button ID="Button1" runat="server" Text="Add">
                            <DirectEvents>
                                <Click OnEvent="AddNewItem">
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:Button ID="Button2" runat="server" Text="Check">
                            <DirectEvents>
                                <Click OnEvent="CheckControl">
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
        </ext:Panel>
        </form>
    </body>
    </html>
    
    
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    
    public partial class Default6 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    
        protected void AddNewItem(object sender, DirectEventArgs e)
        {
            Ext.Net.TextField t = new Ext.Net.TextField
            {
                ID = "t1",
                Width = Unit.Pixel(200)
            };
            t.Text = t.ID;
            Toolbar1.Items.Add(t);
            t.Render();
    
            if (Page.FindControl("t1") != null)
            {
                X.Msg.Alert("", "Yes, find!").Show();    // ->Succeed
            }
            else
            {
                X.Msg.Alert("", "No, Sorry!").Show();
            }
        }
    
        protected void CheckControl(object sender, DirectEventArgs e)
        {
    
            if (Page.FindControl("t1") != null)
            {
                X.Msg.Alert("", "Yes, find!").Show();   // ->Fail
            }
            else
            {
                X.Msg.Alert("", "No, Sorry!").Show();
            }
        }
    }
    Last edited by Daniil; Oct 21, 2010 at 2:23 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Unfortunately ASP.NET is a stateless system. A Page is recreated during each request (DirectEvent), respectively all controls are recreated.
    So, when the CheckControl is executed there is just no the "t1" control in a Page (AddNewItem is not executed during Page's recreation)

    If you want to get a created during DirectEvent control in another DirectEvent this control should be created in the Page_Load or Page_Init, example.

    Please clarify what is you requirement? What actions do you need to apply on "t1' control?
  3. #3
    Thanks Daniil.
    I got it and I give up this method to get the control ID.
    So, Please close this topic.
  4. #4
    Also please note that it's possible to apply all client side operations to a control during DirectEvent.
  5. #5
    You can use X.GetCmp to get the value of a TextField (or any Field) Component that was created during an earlier request.

    Example

    X.GetCmp<TextField>("TextField1").Text
    The X.GetCmp<T> Method will create a proxy instance of T and attempt to set the value (.Text) property from the submitted form values.

    Works only for form submitted values.
    Geoffrey McGill
    Founder

Similar Threads

  1. [CLOSED] How does "MaskCls" work for "AutoLoad" mask in panel control
    By leon_tang in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Jul 19, 2012, 12:09 PM
  2. Replies: 1
    Last Post: Jun 26, 2012, 11:29 AM
  3. Replies: 5
    Last Post: May 02, 2012, 5:37 PM
  4. Replies: 4
    Last Post: Oct 11, 2011, 2:42 AM
  5. Replies: 6
    Last Post: Oct 19, 2010, 12:33 PM

Tags for this Thread

Posting Permissions