[1.0] XControlLoader: XRender from WebService

  1. #1

    [1.0] XControlLoader: XRender from WebService

    The XControlLoader - utilite class, what can render new XControls and change exists from WebService.

            [WebMethod]
            public DirectResponse AddLoginWindow()
            {
                var loader = new XControlLoader();
    
                // Create new XControl and set properties
                var c = loader.Create<LoginWindow>("LoginWindow.ascx", "LoginWindow_" + Guid.NewGuid().ToString().Replace("-", ""), a => a.Wnd);
                c.Wnd.X = 550 - rnd.Next(100);
                c.Wnd.Y = 450 - rnd.Next(100);
                c.txtUsername.Text = "demo";
                c.txtPassword.Text = "demo";
    
                //Call X.AddScript
                X.Msg.Notify("Login Window", "Login Window is showing...").Show();
    
                //Modify already exist control
                var ml = loader.Modify<MessageLabel>("MessageLabel.ascx", "MessageLabel", "lblMessage");
                ml.lblMessage.Text = "Login Window is showing...";
    
                return new DirectResponse(loader.ToScript());
            }
            [WebMethod]
            public DirectResponse Login(string wndid, string jvalues)
            {
                var loader = new XControlLoader();
    
                var id = wndid.Replace("_Wnd", "");
                var c = loader.Modify<LoginWindow>("LoginWindow.ascx", id, a => a.Wnd);
    
                var values = JSON.Deserialize<Dictionary<string, object>>(jvalues);
    
                if (values["Username"].ToString() != "demo")
                {
                    // Call XControl methods
                    c.txtUsername.Focus(true);
                    c.txtUsername.Element.Frame("ff0000");
    
                    //Set XControl properties
                    c.lblStatus.Text = "Error login";
                    c.lblStatus.Icon = Icon.Exclamation;
    
                    //Call X.AddScript
                    X.Msg.Notify("Login invalid", "The username is not exist.").Show();
    
                    return loader;
                }
    
                if (values["Password"].ToString() != "demo")
                {
                    //Set XControls properties
                    c.txtPassword.Text = "";
                    c.lblStatus.Text = "Error password";
                    c.lblStatus.Icon = Icon.ErrorGo;
    
                    loader.AddScript(c.txtPassword.ClientID + ".el.frame('ff0000');");
                    loader += "Ext.Msg.notify('Login invalid', 'The password is invalid.');";
                    return loader;
                }
    
                c.Wnd.Close();
    
                //Modify other control
                var ml = loader.Modify<MessageLabel>("MessageLabel.ascx", "MessageLabel", "lblMessage");
                ml.lblMessage.Html = string.Format(
                    "<br /><b>LOGIN SUCCESS</b><br /><br />Username: {0}<br />Password: {1}",
                    values["Username"], values["Password"]
                );
                X.AddScript(ml.lblMessage.ClientID + ".el.frame('00ffff')");
    
                return loader;
            }
    Sources
    Last edited by Kam; May 03, 2011 at 7:33 AM.
  2. #2
    Hi Kam,

    Thank you for sharing.
  3. #3
    Link to the sources is not working.

Similar Threads

  1. What is the use XRender? Where it can be useful?
    By vjsrinath in forum 1.x Help
    Replies: 4
    Last Post: Feb 14, 2012, 12:06 PM
  2. DirectMethod Not Found. (using XRender)
    By aespinoza in forum 1.x Help
    Replies: 0
    Last Post: Jun 26, 2010, 9:25 PM
  3. [1.0] XRender with child controls
    By lukasw in forum 1.x Help
    Replies: 9
    Last Post: Apr 21, 2010, 6:16 AM
  4. Replies: 6
    Last Post: Apr 07, 2010, 4:18 AM
  5. [CLOSED] XRender UserControl DirectMethod
    By amitpareek in forum 1.x Premium Help
    Replies: 10
    Last Post: Jan 22, 2010, 1:03 PM

Posting Permissions