Sep 05, 2012, 12:48 PM
[CLOSED] Direct event + multiple forms on page
Hello
Hope it's ok to open new thread when the question chagnes even the sample is similar
I have dynamic tabpanel, each tab has form tag in the root, inside the tab I have button with DirectEvent and Direct method call.
Direct event works fine, Direct method does not, I guess I need to say somehow to direct event to send the data of the form with the request, but I don't know how.
Here is the sample:
Hope it's ok to open new thread when the question chagnes even the sample is similar
I have dynamic tabpanel, each tab has form tag in the root, inside the tab I have button with DirectEvent and Direct method call.
Direct event works fine, Direct method does not, I guess I need to say somehow to direct event to send the data of the form with the request, but I don't know how.
Here is the sample:
<%@ Import Namespace="Newtonsoft.Json" %>
<%@ Import Namespace="Newtonsoft.Json.Linq" %>
<script runat="server">
protected void Button1_Click(object sender, DirectEventArgs e)
{
int key = -1;
var configStr = Request["submitDirectEventConfig"];
if (string.IsNullOrEmpty(configStr) == false)
{
JsonObject obj = JsonConvert.DeserializeObject<JsonObject>(configStr);
JObject configObj = (JObject)obj["config"];
var val = configObj["extraParams"];
if (string.IsNullOrEmpty(val["hid"].Value<string>()) == false)
key = val["hid"].Value<int>();
hid.Value = key;
}
hid.Value = (key).ToString();
if (string.IsNullOrEmpty(hid.Value as string))
{
hid.Value = "0";
}
else
{
hid.Value = (int.Parse(hid.Value as string) + 1).ToString();
}
UserControl uc1 = (UserControl)this.LoadControl("~/WindowsApp/UserControls/TextControll.ascx");
uc1.ID = "UC" + hid.Value;
var pnl = new Ext.Net.Panel()
{
ID = "dynamicPanel" + hid.Value,
Title = "Tab" + hid.Value,
CloseAction = CloseAction.Destroy,
Closable = true
};
pnl.ContentControls.Add(uc1);
pnl.Render("tabPanel", RenderMode.AddTo);
}
protected override void OnInit(EventArgs e)
{
var key = Request.Form.AllKeys.FirstOrDefault(item => item.Contains("hiddenField"));
if (string.IsNullOrEmpty(key) == false)
{
var countStr = Request[key];
if (countStr != null && countStr != "")
{
int count = int.Parse(countStr);
UserControl uc1 = (UserControl)this.LoadControl("~/WindowsApp/UserControls/TextControll.ascx");
uc1.ID = "UC" + count;
var pnl = new Ext.Net.Panel()
{
ID = "dynamicPanel" + count,
};
pnl.ContentControls.Add(uc1);
tabPanel.Controls.Add(pnl);
}
}
base.OnInit(e);
}
</script>
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<title>Update Controls and Content during a DirectEvent - Ext.NET Examples</title>
</head>
<body>
<script src="http://ala-test.allynintl.eu/ALAJavaScripts.ashx" type="text/javascript"></script>
<script>
function test(con, options, eOpts, params) {
params.hid = hid.getValue();
params.yyy = 'xxx';
}
Ext.onReady(function () {
})
</script>
<form id="aspnetForm">
</form>
<ext:ResourceManager ID="ResourceManager1" runat="server" Namespace="">
<Listeners>
<BeforeAjaxRequest Fn="test">
</BeforeAjaxRequest>
</Listeners>
</ext:ResourceManager>
<ext:Hidden runat="server" ID="hid" />
<ext:TabPanel ID="tabPanel" runat="server" Title="Tab with dynamic controls" Width="1000"
Height="800" BodyPadding="5">
<TopBar>
<ext:Toolbar ID="Toolbar1" runat="server">
<Items>
<ext:Button runat="server" Text="Add" OnDirectClick="Button1_Click">
<DirectEvents>
<Click>
<ExtraParams>
<ext:Parameter Name="hid" Value="#{hid}.getValue()" Mode="Raw" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
</ext:TabPanel>
</body>
</html>
<form>
<script>
function directEvent() {
Ext.net.DirectMethods.<%= ClientID %>.DirectMethod({
// smthing to be added here?
});
}
</script>
<ext:Hidden runat="server" ID="hiddenField" />
<ext:FormPanel runat="server">
<Items>
<ext:TextField runat="server" ID="txt1">
</ext:TextField>
<ext:Button runat="server" ID="btn" OnDirectClick="btnVoidTR_click" Text="Click me Direct Event">
</ext:Button>
<ext:Button runat="server" ID="btnMethod" Text="Click me Direct Method">
<Listeners>
<Click Fn="directEvent"></Click>
</Listeners>
</ext:Button>
</Items>
</ext:FormPanel>
</form>
Last edited by Daniil; Sep 12, 2012 at 6:02 AM.
Reason: [CLOSED]