PDA

View Full Version : [1.0] XControlLoader: XRender from WebService



Kam
Apr 29, 2011, 5:26 PM
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 (https://rapidshare.com/files/460357202/XControlLoader101.zip)

Daniil
May 02, 2011, 5:23 AM
Hi Kam,

Thank you for sharing.

Svr77
Nov 11, 2011, 2:49 PM
Link to the sources is not working.