PDA

View Full Version : [CLOSED] Button disappears on Render in DirectEvent.



michaeld
Nov 28, 2013, 9:53 AM
<%@ Page Language="C#" %>


<script runat="server">
protected void Page_Load( object sender, EventArgs e ) {
}
protected void OnClick( object sender, DirectEventArgs e ) {
// Setup Goto Button
GotoB.Listeners.Click.Handler = "alert('Test');";
GotoB.Render();
GotoB.Enable();
}
</script>
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<title>Test43</title>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" ScriptMode="Debug" SourceFormatting="true" />


<ext:Viewport ID="vp" runat="server" Layout="VBoxLayout">
<LayoutConfig>
<ext:VBoxLayoutConfig Align="Stretch" />
</LayoutConfig>
<Items>


<ext:Panel ID="P" runat="server" Border="false" Padding="3" Flex="1" Title="Test43" Layout="VBoxLayout">
<LayoutConfig>
<ext:VBoxLayoutConfig Align="Stretch" />
</LayoutConfig>
<Items>
<ext:Label ID="Lbl" runat="server" Flex="1" Text="test" />
</Items>
<Buttons>
<ext:Button ID="Button1" runat="server" Text="Click to add Listener" Type="Submit">
<DirectEvents>
<Click OnEvent="OnClick" />
</DirectEvents>
</ext:Button>


<ext:Button ID="GotoB" runat="server" Text="Alert" Type="Submit" Icon="DatePrevious" Disabled="true">
</ext:Button>


</Buttons>
</ext:Panel>


</Items>
</ext:Viewport>
</form>
</body>
</html>

The response code seems good but yet Alert button disappears.


{"script":"Ext.net.ResourceMgr.destroyCmp(\"App.GotoB\");App.P.add({\"id\":\"GotoB\",\"disabled\":true,\"iconCls\":\"#DatePrevious\",\"text\":\"Alert\",\"type\":\"submit\",\"listeners\":{\"click\":{\"fn\":function(item,e){alert('Test');}}}});App.GotoB.en able();"}


All I'm trying to do is replace the listener. Replacing listeners seems to be quite a challenge on the server-side.

Vladimir
Nov 28, 2013, 10:06 AM
Instead Render you need to use ReRender method.
We will try to improve Render method to avoid mixing Render and ReRender

michaeld
Nov 28, 2013, 10:27 AM
<%@ Page Language="C#" %>


<script runat="server">
protected void Page_Load( object sender, EventArgs e ) {
}
protected void OnClick( object sender, DirectEventArgs e ) {
// Setup Goto Button
//GotoB.Listeners.Click.Handler = "alert('" + cnt++.ToString() + "');";
//GotoB.Render();
GotoB.ClearListeners();
int cnt = Convert.ToInt32( Cnt.Value );
GotoB.On( "click", new JFunction( "alert('" + cnt++.ToString() + "');" ) );
Cnt.Value = cnt;
GotoB.Enable();
}
</script>
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<title>Test43</title>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" ScriptMode="Debug" SourceFormatting="true" />


<ext:Viewport ID="vp" runat="server" Layout="VBoxLayout">
<LayoutConfig>
<ext:VBoxLayoutConfig Align="Stretch" />
</LayoutConfig>
<Items>


<ext:Panel ID="P" runat="server" Border="false" Padding="3" Flex="1" Title="Test43" Layout="VBoxLayout">
<LayoutConfig>
<ext:VBoxLayoutConfig Align="Stretch" />
</LayoutConfig>
<Items>
<ext:NumberField ID="Cnt" runat="server" Flex="1" Text="0" />
</Items>
<Buttons>
<ext:Button ID="Button1" runat="server" Text="Click to add Listener" Type="Submit">
<DirectEvents>
<Click OnEvent="OnClick" />
</DirectEvents>
</ext:Button>


<ext:Button ID="GotoB" runat="server" Text="Alert" Type="Submit" Icon="DatePrevious" Disabled="true">
</ext:Button>


</Buttons>
</ext:Panel>


</Items>
</ext:Viewport>
</form>
</body>
</html>


Clicking Alert Button does not alert.



Instead Render you need to use ReRender method.
Vladimir, ReRender() works. Thanks.

Daniil
Nov 28, 2013, 1:42 PM
The ClearListeners call removes all the listeners including the internal ones.

For example, a Button have a listener which listen to the click event on the underlying button's HTML element. This listeners re-fires the Click event on the Button as a component. A ClearListeners call removes that listener as well.