DisableControl="true" on CodeBehind

  1. #1

    DisableControl="true" on CodeBehind

    Hi,

    I'm trying to copy the behaviour of DisableControl in Codebehind.

    for example, in my .aspx file I got this button and it works fine:

     <ext:ImageButton
                            
                            id="botonmas"
                            MinWidth="10"
                            Width="45"
                            Height="45"
                            class="tip-target"
                            ToggleGroup="GroupRss"
                            MarginSpec="0 0 0 10"
                            runat="server"
                            ImageUrl="/img/more.png"
                            OverImageUrl="/img/more(1).png">
                            <DirectEvents>
                                <Click DisableControl="true" OnEvent="CargarMas"></Click>
                            </DirectEvents>
                            
                        </ext:ImageButton>
    I want make the same thing in codebehing, but I dont get to know how to do it.

    Here is the button in codebehind where I want to do it.
    Ext.Net.ImageButton btnañadir = new Ext.Net.ImageButton();
                    btnañadir.ID = "btnañadir" + nitem.ToString();
                    btnañadir.MinWidth = 10;
                    btnañadir.Width = 79;
                    btnañadir.Height = 32;
                    btnañadir.ImageUrl = "/img/button_anadir.png";
                    btnañadir.OverImageUrl = "/img/button_anadir(1).png";
                    panelbtnañadir.Add(btnañadir);
    
                    btnañadir.Listeners.Click.Handler = "App.direct.VistaDetallada(e.clientY,'" + item.Modelo.TrimEnd() + "','" + btnañadir.ID + "')";
    thank You
  2. #2
    Hello, @PascuV!

    You just set the button direct event's DisableControl as true just like you do in markup.

    For instance:

    btnañadir.DirectEvents.Click.DisableControl = true;
    If your code is still not working, that might be another reason, a topic rather explored already here in forums, so I will just link you some discussions related to it. Let us know if you still don't get it working the way you need.

    - DirectEvent: Click Event in code behind troubles
    - Adding A Menu Item with a DirectEvent from a Page_Load

    Basically, if you fall in this issue, is because you are not persisting the control between requests. When you draw a component from markup, it is always available to code behind (its initial state) no matter what. When you dynamically set it from code behind, it will exist to the server only during the request.

    What I missed in the threads linked above is the actual code to add the component every request. It should be added every time a request happens, but adding it at the time the specific direct event code runs does not suffice. One "sure shot" location would be the Page_Load event, as long as you ensure it runs regardless of isPostBack and Ext.Net.IsAjaxRequest status:

    this.Page.Controls.Add(btnañadir);
    Hope this helps!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 8
    Last Post: Aug 11, 2015, 2:52 PM
  2. Replies: 1
    Last Post: Oct 05, 2012, 12:56 PM
  3. [CLOSED] Hidden="true" behaves as Visible="false"
    By marco.morreale in forum 2.x Premium Help
    Replies: 5
    Last Post: May 28, 2012, 4:17 PM
  4. Replies: 5
    Last Post: May 02, 2012, 6:37 PM
  5. [CLOSED] DropDownField with Grow="true" and GrowMax="xxx"
    By deejayns in forum 1.x Premium Help
    Replies: 4
    Last Post: Jan 12, 2012, 1:00 PM

Posting Permissions