[CLOSED] [1.0] How to access a direct method event inside a user control

  1. #1

    [CLOSED] [1.0] How to access a direct method event inside a user control

    Hi,

    I need to access the direct method event which is declared inside a user control which is created dynamically inside a window.

    This is my scenario,

    I am opening a window on clicking a button in the parent page (Sample.aspx). In the window im loading the user control(Sample.ascx). I have got a save button in user control(sample.ascx). Now when i click the save button, i have to call a DirectMethod in the user control (sample.ascx).

    This is my sample code.

    Sample.aspx:

    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Sample.aspx.vb" Inherits="Zangle.NET.Sample" %>
    
    <%@ 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>Untitled Page</title>
    
    </head>
    
    <body>
    
    <form runat="server">
    
    <ext:ResourceManager ID="ResourceManager1" runat="server">
    
    </ext:ResourceManager>
    
    <ext:Panel runat="server" Title="Student Search" Border="false" BodyStyle="padding:3px">
    
    <Items>
    
    <ext:Button ID="btnOpen" runat="server" Text="Open">
    
    <DirectEvents>
    
    <Click OnEvent="openButtonClick">
    
    <EventMask ShowMask="true" Msg="Loading..." />
    
    </Click>
    
    </DirectEvents>
    
    </ext:Button>
    
    </Items>
    
    </ext:Panel>
    
    </form>
    
    </body>
    
    </html>
    Sample.aspx.vb:

    Imports Ext.Net
    
    Partial Public Class Sample
    
    Inherits System.Web.UI.Page
    
    ''' <summary>
    
    ''' Handles the Click event of the StudentFindButton control.
    
    ''' </summary>
    
    ''' <param name="sender">The source of the event.</param>
    
    ''' <param name="e">The <see cref="Ext.Net.DirectEventArgs" /> instance containing the event data.</param>
    
    Protected Sub openButtonClick(ByVal sender As Object, ByVal e As DirectEventArgs)
    
    Dim win As New Ext.Net.Window
    
    win.ID = "StudentEditStatus"
    
    win.Title = "Student Editor"
    
    win.Height = 120
    
    win.Width = 140
    
    win.ContentControls.Add(Me.LoadControl("SampleControl.ascx"))
    
    win.Render(Me.Form)
    
    End Sub
    
    End Class
    Sample.ascx:

    <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="SampleControl.ascx.vb"
    
    Inherits="Zangle.NET.SampleControl" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <ext:Panel runat="server">
    
    <Buttons>
    
    <ext:Button ID="StatusSaveButton" runat="server" Text="Save">
    
    <Listeners>
    
    <Click Handler="Ext.net.DirectMethods.SaveClick();" />
    
    </Listeners>
    
    </ext:Button>
    
    </Buttons>
    
    <Content>
    
    <ext:FormLayout ID="FormLayout1" runat="server" LabelAlign="Left" LabelSeparator="">
    
    <Anchors>
    
    <ext:Anchor>
    
    <ext:TextField ID="TrackTextField" runat="server" FieldLabel="Track*"
    
    Width="200px">
    
    </ext:TextField>
    
    </ext:Anchor>
    
    </Anchors>
    
    </ext:FormLayout>
    
    </Content>
    
    </ext:Panel>
    
     
     Sample.ascx.vb:
    
    Imports Ext.Net
    
    Partial Public Class SampleControl
    
    Inherits System.Web.UI.UserControl
    
    <DirectMethod()> _
    
    Public Sub SaveClick()
    
    TrackTextField.Text = "Saved"
    
    End Sub
    
    End Class
    Could you tell me how to access the SaveClick DirectMethod of the usercontrol..

    When i run the application, im getting the error as --Microsoft JScript runtime error: Object doesn't support this property or method..

    I also need to know, how to give ID property for the usercontrol which is loaded dynamically inside the window.
    Once i give the ID property, then i think i can able to access the method by the following way,

    Ext.net.DirectMethods.ID.SaveClick().. Is that correct ?..

  2. #2

    RE: [CLOSED] [1.0] How to access a direct method event inside a user control

    Does the following example help solve the problem, see https://examples1.ext.net/#/Events/D.../UserControls/

    You can (and should) set the .ID property of the UserControl before adding to the .ContentControls collection.


    Hope this helps.


    Geoffrey McGill
    Founder
  3. #3

    RE: [CLOSED] [1.0] How to access a direct method event inside a user control

    Hi,

    Also please note that you have to recreate user control on each request otherwise the toolkit is not able to find the direct method
  4. #4

    RE: [CLOSED] [1.0] How to access a direct method event inside a user control

    Could you tell me, how to add the ID property for the usercontrol, when adding that control dynamically inside the window.

    Dim win As New Ext.Net.Window


    win.Title = "Student Editor"


    win.Height = 420


    win.Width = 420


    win.ContentControls.Add(Me.LoadControl("~/Controls/StudentEditor/StudentStatusUpdate.ascx"))


    win.Render(Me.Form)
  5. #5

    RE: [CLOSED] [1.0] How to access a direct method event inside a user control

    You get an instance of the Control, then set the .ID property.


    Control status = this.LoadControl("~/Controls/StudentEditor/StudentStatusUpdate.ascx");status.ID = "Status1";

    Hope this helps.


    Geoffrey McGill
    Founder
  6. #6

    RE: [CLOSED] [1.0] How to access a direct method event inside a user control

    I have added the ID for the usercontrol and added the following code to call the DirectMethod, but im getting the error as "The control with ID 'SampleUC' not found".
    My sample code is,

    Sample.aspx.vb

    Dim win As New Ext.Net.Window
    win.ID = "StudentEditStatus"
    win.Title = "Student Editor"
    win.Height = 120
    win.Width = 140
    Dim status As Control = Me.LoadControl("SampleControl.ascx")
    status.ID = "SampleUC"
    win.ContentControls.Add(status)
    win.Render(Me.Form)
    Sample.ascx

    <ext:Button ID="StatusSaveButton" runat="server" Text="Save">
        <Listeners>
            <Click Handler="Ext.net.DirectMethods.SampleUC.SaveClick();" />
        </Listeners>
    </ext:Button>
  7. #7

    RE: [CLOSED] [1.0] How to access a direct method event inside a user control

    I believe the answer to your problem is here:

    vladimir (5/19/2010)Hi,


    Also please note that you have to recreate user control on each request otherwise the toolkit is not able to find the direct method
    ... or find the button on the usercontrol
  8. #8

    RE: [CLOSED] [1.0] How to access a direct method event inside a user control

    it may be just a typo, but you refer to your usercontrol as
    "sample.ascx"
    --------------------
    Sample.ascx
    --------------------
    in your last code snippet , but you then write
    Me.LoadControl("SampleControl.aspx")
    in your code
  9. #9

    RE: [CLOSED] [1.0] How to access a direct method event inside a user control

    Can you guys add an advanced sample to your examples explorer that actually shows how from within a DirectEvent runtime to call LoadControl to invoke a user control that has its own DirectEvents that may be invoked? This forum thread is one of few reasources I've found that comes close to this. Moreover, the author calls Render() which so far as I can tell doesn't seem to render the entire user control, just the extjs parts of it.

Similar Threads

  1. Replies: 2
    Last Post: Oct 12, 2011, 7:49 AM
  2. Replies: 1
    Last Post: Jul 25, 2011, 9:59 AM
  3. Replies: 7
    Last Post: Jun 28, 2011, 11:13 AM
  4. Replies: 8
    Last Post: Jan 25, 2011, 4:21 AM
  5. Replies: 1
    Last Post: Mar 09, 2010, 2:55 AM

Posting Permissions