PDA

View Full Version : [CLOSED] Set a buttons DirectEvent through another DirectEvent



dataworks
Jun 04, 2014, 10:54 PM
Im trying to set a buttons DirectEvent through another DirectEvent from another button but it does not fire. Help please


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />

<ext:Panel runat="server">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" ID="btnTest" Text="Test">
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Items>
<ext:Button runat="server" ID="btnSetEvent" Text="Set Event">
<DirectEvents>
<Click OnEvent="SetEvent" />
</DirectEvents>
</ext:Button>
</Items>
</ext:Panel>

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


public partial class TestPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

public void Click_Event(object sender, DirectEventArgs e)
{
X.Msg.Alert("Test", "Test").Show();
}

public void SetEvent(object sender, DirectEventArgs e)
{
btnTest.DirectEvents.Click.Event += Click_Event;
}

}

Daniil
Jun 05, 2014, 6:11 AM
Hi @dataworks,

Yes, it is not going to work for some reasons.

If you need to attach a server side handler on the fly you can use a combination of a client side listener and a DirectMethod. There is no problem to attach a client side listener on the fly. Please use the AddListener and On methods.

dataworks
Jun 05, 2014, 1:20 PM
Hello Daniil. Reason I need a DirectEvent is to trigger a file download so I need to set IsUpload="true". Is there a workaround for this? Or a way to do as listener? Thanks

Daniil
Jun 05, 2014, 1:36 PM
It is possible with a DirectMethod.


App.direct.DirectMethodName({
isUpload : true,
formId : "form id"
});

dataworks
Jun 05, 2014, 1:53 PM
Thanks for the response Daniil. Having a hard time here. I set the listener through:


btnTest.Listeners.Click.Handler = "App.direct.Download({isUpload: true, formId: 'form1'})";

But nothing happenes. Then tried using:


btnTest.AddListener("click", "App.direct.Download({isUpload: true, formId: 'form1'})");

But the event fires when the listener is added (when btnSetEvent is clicked and not when btnTest is clicked).


public partial class TestPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

public void Click_Event(object sender, DirectEventArgs e)
{
X.Msg.Alert("Test", "Test").Show();
}

public void SetEvent(object sender, DirectEventArgs e)
{
btnTest.Listeners.Click.Handler = "App.direct.Download({isUpload: true, formId: 'form1'})";
//btnTest.AddListener("click", "App.direct.Download({isUpload: true, formId: 'form1'})");
}

[DirectMethod]
public void Download()
{
Response.Clear();
Response.ClearHeaders();
Response.Buffer = true;
Response.AddHeader("Content-Length", FileMgr.getContent("C:/test.txt").Length.ToString());
Response.ContentType = "text/plain";
Response.AddHeader("Content-Disposition", "attachment;filename=" + Server.HtmlEncode("test.txt"));
Response.BinaryWrite(FileMgr.getContent("C:/test.txt"));
Response.Flush();
Response.End();
}
}



<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />

<ext:Panel runat="server">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" ID="btnTest" Text="Test">
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Items>
<ext:Button runat="server" ID="btnSetEvent" Text="Set Event">
<DirectEvents>
<Click OnEvent="SetEvent" />
</DirectEvents>
</ext:Button>
</Items>
</ext:Panel>

</form>

Daniil
Jun 05, 2014, 1:55 PM
Please try:

btnTest.AddListener("click", "function() { App.direct.Download({isUpload: true, formId: 'form1'}) }");

dataworks
Jun 05, 2014, 2:03 PM
Works! Thank you very much Daniil.

dataworks
Jun 05, 2014, 8:14 PM
Ive been searching for a while but haven't had luck. I want to send a parameter to the DirectMethod defined on the listener. Thanks


Ext.Net.MenuItem mni = new Ext.Net.MenuItem();
mni.ID="mniRev"+row["EXPEDIENTE_RENEWAL_FORM"].ToString();
mni.Text="Revisi?n: "+row["EXPEDIENTE_RENEWAL_FORM"].ToString();
mni.AddListener("click", "function() { App.direct.Click_Event({isUpload: true, formId: 'form1'}); }");
mni.Render(mnuPrint, RenderMode.AddTo, true);



[DirectMethod]
public void Click_Event(string revID)
{
OpenPrint(revID);
}

geoffrey.mcgill
Jun 05, 2014, 10:07 PM
I want to send a parameter to the DirectMethod defined on the listener

Just pass it as the first argument of the function call, and your optional config as the second argument.

Daniil
Jun 06, 2014, 4:29 AM
Also there is an example of that, please see #3:
http://examples2.ext.net/#/Events/DirectMethods/Overview/