PDA

View Full Version : [CLOSED] Different behaviors in DirectEvent between UserControlLoader and UserControl



michaeld
Sep 10, 2013, 5:32 AM
ascx


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Test31a.ascx.cs" Inherits="Test31a" %>


<ext:Window ID="TW" runat="server" Title="Add Something" Width="500" Modal="true">
<Items>


<ext:FormPanel ID="FP" runat="server" BodyPadding="5" BodyStyle="background:white;" Height="400"
Layout="FitLayout">
<Items>
<ext:Label ID="Label1" runat="server" Html="Sample Text" Padding="5" Flex="1" />
<ext:MultiSelect ID="MS" runat="server" HideLabel="true"
BodyPadding="5" StyleSpec="padding-left:10px;" Border="false" Width="110" Height="300" ShowCheckbox="true">
<Items>
<ext:ListItem Text="1" Value="1" />
<ext:ListItem Text="2" Value="2" />
<ext:ListItem Text="3" Value="3" />
</Items>
<Listeners>
<Render Handler="#{MS}.setSelectedItems(#{MS}.store.getAllRange());" />
</Listeners>
</ext:MultiSelect>
</Items>
<Buttons>
<ext:Button ID="Submit" runat="server" Text="Submit" Type="Submit">
<DirectEvents>
<Click OnEvent="OnAdd">
<EventMask ShowMask="true" MinDelay="500" Msg="Adding..." />
</Click>
</DirectEvents>
</ext:Button>
</Buttons>
</ext:FormPanel>


</Items>
</ext:Window>



ascx.cs


using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;


public partial class Test31a : UserControl {
protected void Page_Load( object sender, EventArgs e ) {
if( !X.IsAjaxRequest )
TW.Show();
}


protected void OnAdd( object sender, DirectEventArgs e ) {
var items = MS.SelectedItems;
int len = items.Count;
X.Msg.Alert( "Items", len.ToString() );
}
}

aspx


<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>


<script runat="server">
protected void Page_Load( object sender, EventArgs e ) {
var ctl = Page.LoadControl( "Test31a.ascx" );
ctl.ID = "TaskUC" + 1.ToString();
Page.Controls.Add( ctl );
}
</script>


<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<title>Test31a</title>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" ViewStateMode="Enabled" ScriptMode="Debug" SourceFormatting="true" />


<ext:Viewport ID="vp" runat="server">
</ext:Viewport>


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


This version does trap in OnAdd and len does seem to contain the count of selected items.

However, this slight change in the aspx Page_Load to the following does not.


protected void Page_Load( object sender, EventArgs e ) {
var ctl = new UserControlLoader( new UserControlLoader.Config() { Path = "Test31a.ascx" } );
ctl.UserControlID = "TaskUC" + 1.ToString();
vp.Bin.Add( ctl );
}





I should note also that both fail to display the alert.

Daniil
Sep 10, 2013, 6:04 AM
Hi @michaeld,

Running your initial test case (without a UserControlLoader) I can state that it is not true for me:

IThis version does trap in OnAdd and len does seem to contain the count of selected items.

It is zero for me. And, as far as I can see, it should be zero, because you add a Window in the Page.Controls. It means it is not falling into the <form>. With this:

this.Form.Controls.Add( ctl );
the selected items get submitted.

As for a UserControlLoader. It seems to be working for me without any changes.


I should note also that both fail to display the alert.

You should call the Show method.

X.Msg.Alert("Items", len.ToString()).Show();

michaeld
Sep 10, 2013, 7:26 AM
Running your initial test case (without a UserControlLoader) I can state that it is not true for me:

It is zero for me. And, as far as I can see, it should be zero, because you add a Window in the Page.Controls. It means it is not falling into the <form>.


This strategy was at the advice of vladimir in http://forums.ext.net/showthread.php?26381-Window-not-rendering/page2

He may not have considered the post-back consequences or I may have misunderstood his direction. I'll consider instead your suggestion of this in the future:


With this:

this.Form.Controls.Add( ctl );
the selected items get submitted.


Ultimately this should address my non-sample code that shared the same problem.


As for a UserControlLoader. It seems to be working for me without any changes.
This was what I was trying to establish.



You should call the Show method.

X.Msg.Alert("Items", len.ToString()).Show();

Sorry. My intuition keeps failing me that the Alert is returning an object; that it's not a method. I often manage to forget the Show() part. Thanks for the reminder.

Daniil
Sep 11, 2013, 6:56 AM
This strategy was at the advice of vladimir in http://forums.ext.net/showthread.php?26381-Window-not-rendering/page2

He may not have considered the post-back consequences or I may have misunderstood his direction.


Well, he didn't mean adding direct to Page.Controls. So, if you need to get the controls submitted, please add them to Form. A Form is inside a page. So, it doesn't conflicts with the Vladimir's suggestion.



Sorry. My intuition keeps failing me that the Alert is returning an object; that it's not a method. I often manage to forget the Show() part. Thanks for the reminder.

The same happens for me as well sometimes:)