[CLOSED] XScript as server control

  1. #1

    [CLOSED] XScript as server control

    Can you provide a simple example of the syntax used for instantiating an Ext,Net,Xscript object on server side and loading it with a script and adding to page. Something like:
    Dim sb As Stringsb = "<script type="text/javascript">alert('test');</script>"
    Dim xSrpt As New Ext.Net.XScript()
    xSrpt.AddScript(sb) 
    Me.Add(xSrpt)
    The xscript is created inside a custom control that exists in markup and contains javascript functionality that will be used by the control.
    Last edited by Daniil; Jun 11, 2012 at 2:07 PM. Reason: [CLOSED]
  2. #2
    Hi @betamax,

    I would implement it something like this.

    Example
    <%@ Page Language="C#" %>
     
    <%@ 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>Ext.NET Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:Button ID="Button1" runat="server" Text="Click me">
            <Bin>
                <ext:Container runat="server">
                    <Content>
                        <ext:XScript runat="server">
                            <script type="text/javascript">
                                var onClick = function (btn) {
                                    alert("Hello from " + btn.id + "!");
                                };
                            </script>
                        </ext:XScript>    
                    </Content>
                </ext:Container>
            </Bin>
            <Listeners>
                <Click Fn="onClick" />
            </Listeners>
        </ext:Button>
    </body>
    </html>
    Please clarify what is the initial requirement which has pushed you to use XScript? What is the base control of the custom control?

    Maybe, there is a better solution.
  3. #3

    instantiating an Ext,Net,Xscript object on server side

    Yes. Now, can you provide a simple example of the syntax used for instantiating an Ext,Net,Xscript object on server side.

    If its not done, or can't be, that's fine. I don't need to do this; I have already coded using traditional means. It is more of a curiosity why my code threw a Object Reference exception at the point where I call addscript method on the new object than anything.

    We use XScript throughout our app primarily for its shorthand functionality. In this case it would be a way to encapsulate server-side dynamically generated javascript that uses the shortcut functionality.

    The control inherits from gridpanel.

    Quote Originally Posted by Daniil View Post
    Hi @betamax,

    I would implement it something like this.

    Example
    <%@ Page Language="C#" %>
     
    <%@ 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>Ext.NET Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
        <ext:Button ID="Button1" runat="server" Text="Click me">
            <Bin>
                <ext:Container runat="server">
                    <Content>
                        <ext:XScript runat="server">
                            <script type="text/javascript">
                                var onClick = function (btn) {
                                    alert("Hello from " + btn.id + "!");
                                };
                            </script>
                        </ext:XScript>    
                    </Content>
                </ext:Container>
            </Bin>
            <Listeners>
                <Click Fn="onClick" />
            </Listeners>
        </ext:Button>
    </body>
    </html>
    Please clarify what is the initial requirement which has pushed you to use XScript? What is the base control of the custom control?

    Maybe, there is a better solution.
  4. #4
    Quote Originally Posted by betamax View Post
    Yes. Now, can you provide a simple example of the syntax used for instantiating an Ext,Net,Xscript object on server side.

    If its not done, or can't be, that's fine. I don't need to do this; I have already coded using traditional means. It is more of a curiosity why my code threw a Object Reference exception at the point where I call addscript method on the new object than anything.
    Please use the XScript ScriptBlock property.

    Example
    <%@ Page Language="C#" %>
      
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            string script = @"var onClick = function (btn) {
                                 alert('Hello from ' + btn.id + '!');
                             };";
    
            XScript xscript = new XScript();
            xscript.ScriptBlock = script;
    
            Container ct = new Container();
            ct.ContentControls.Add(xscript);
            
            Ext.Net.Button btn = new Ext.Net.Button();
            btn.ID = "Button1";
            btn.Text = "Click me";
            btn.Listeners.Click.Fn = "onClick";
            btn.Bin.Add(ct);
    
            this.Controls.Add(btn);
        }
    </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>
        <ext:ResourceManager runat="server" />
    </body>
    </html>
    Quote Originally Posted by betamax View Post
    We use XScript throughout our app primarily for its shorthand functionality. In this case it would be a way to encapsulate server-side dynamically generated javascript that uses the shortcut functionality.

    The control inherits from gridpanel.
    Ok, thanks for the clarification. Well, it is really comfortable to use XScript to encapsulate scripts.
  5. #5
    Thanks Daniil. Exactly what I was looking for.

    I was curious why you used Content instead of Items in the markup example?

    <ext:Container runat="server">    
        <Content> 
            <ext:XScript runat="server">
    Its the first time I've seen the need to put an Ext control in a Content context.
  6. #6
    The Items property is the collection of components in this container. The "components" means inheritors of the JavaScript Ext.Component class (respectively, the Ext.Net.Component server class)
    http://docs.sencha.com/ext-js/3-4/#!...iner-cfg-items

    The XScript class is not an inheritor of the Extt.Net.Component class. So, it should not be placed into the Items collection.
  7. #7

    [Closed]

    Excellent answer and backup link. Thanks.

    Please mark as closed

Similar Threads

  1. [CLOSED] AjaxMethod in Custom Server Control
    By jon in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 30, 2016, 2:18 PM
  2. Replies: 11
    Last Post: Mar 20, 2013, 4:43 PM
  3. [CLOSED] ASP.NET Server Control inside FormPanel
    By UnifyEducation in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: May 25, 2012, 11:07 AM
  4. [CLOSED] Create web server control (composite control)
    By mmmartins in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: May 13, 2011, 6:18 PM
  5. [CLOSED] XScript server error
    By armadalabs in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Feb 17, 2010, 8:28 AM

Posting Permissions