PDA

View Full Version : [CLOSED] Adding code behind controls to form



tMp
Jan 02, 2014, 3:58 PM
Hi

I know that it has something to do with the adding my code behind controls to the form controls when creating them on the fly by direct method. I thought I am doing it but I still have some troubles to see everything though.

What am I doing wrong in this example? I just want to be able to control the store in the first window...


<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{

}
}

[DirectMethod]
public void createWindowOne()
{
Window win = new Window
{
ID = "wOne",
Title = "Window One",
Modal = true,
Width = 200,
Height = 200,
Items =
{
new GridPanel {
ID = "gpWONE",
Height = 100,
Store = {
new Ext.Net.Store
{
ID = "STORE1",
Model = {
new Ext.Net.Model {
Fields = { new Ext.Net.ModelField { Name = "ID", Type = Ext.Net.ModelFieldType.String } },
IDProperty = "ID"
}
}
}
},
ColumnModel = { Columns = { new Ext.Net.Column { Text = "ID", DataIndex = "ID", MenuDisabled = true, Width = 100 } } }
},
new Ext.Net.Button { Text = "Create Window Two", Handler = "App.direct.createWindowTwo();"}
}
};
this.Form.Controls.Add(win);
win.Render(this.Form);
}

[DirectMethod]
public void createWindowTwo()
{
Window win = new Window
{
ID = "wTwo",
CloseAction = Ext.Net.CloseAction.Destroy,
Title = "Window Two",
Modal = true,
Items =
{
new TextField { ID = "tfID", FieldLabel = "Insert ID", Width = 200 },
new Ext.Net.Button { ID = "btnWTWO", Text = "Get Store Count from Window One", Handler = "alert(#{STORE1}.getCount()); #{wTwo}.close();" }
}
};
this.Form.Controls.Add(win);
win.Render(this.Form);
}

</script>

<!DOCTYPE html>

<html>
<head id="Head1" runat="server">
<title></title>

</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />

<ext:Button runat="server" Text="Create Window One" Handler="App.direct.createWindowOne();"></ext:Button>

</form>
</body>
</html>

thank you for any input.

best regards and a happy new year!

Vladimir
Jan 02, 2014, 8:16 PM
Replace '#{STORE1}' by 'App.STORE1' and '#{wTwo}' by 'App.wTwo' because those controls are not accessable during second window creation

michaeld
Jan 03, 2014, 1:36 AM
I would use string.Format("alert({0}.getCount()); {1}.close();", STORE1.ClientID, wTwo.ClientID ) for the handler to ensure they change with idmode usage.

tMp
Jan 03, 2014, 8:37 PM
@Vladimir

Thank you. The "App.xxx" does the trick but I only need it for the store. The window ID is the same window I am generating at that time so the .close() is working.

@michaeld

Could you elaborate what do you mean with IDmode? I have never used it yet and I have no clue what it is. A hint or a link would be very appreciated. Your version didn't yet work for me because I can't reference the STORE1.ClientID at that time during the creation of the second window.

Thank you very much both or you.

geoffrey.mcgill
Jan 03, 2014, 9:39 PM
I would use string.Format("alert({0}.getCount()); {1}.close();", STORE1.ClientID, wTwo.ClientID ) for the handler to ensure they change with idmode usage.

@michaeld - Using the Id token should output the correct client-side Id based on the .IDMode.

Using either #{STORE1} or this.Store1.ClientID should render the same value, no matter what the .IDMode.

tMp
Jan 07, 2014, 11:43 PM
Where can I get more information about this IDmode?

Daniil
Jan 08, 2014, 6:59 AM
Some details of IDMode you can find here:
http://forums.ext.net/showthread.php?12957&p=73893&viewfull=1#post73893

Most of the statements are actual for v2 as well.

tMp
Jan 08, 2014, 12:15 PM
@Daniil

Wonderfull, thank you. You can close this thread - all my questions are answered.