PDA

View Full Version : [CLOSED] UserControlLoader getValue from DirectMethod



CPA1158139
Oct 09, 2014, 3:43 PM
I want to set [DirectMethod] strA() in a.aspx to txtb in b.ascx
I don't know Button1_Click content in a.aspx
I don't know how to get strA() from a.aspx in b.ascx

pls help me, thanks very much.

a.aspx


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

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

<script runat="server">

protected void Page_Init(object sender, EventArgs e)
{
UserControlLoader ul1 = new UserControlLoader();
ul1.ID = "uc1";
ul1.Path = "b.ascx";
Panel1.Items.Add(ul1);
}

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

}
}

[DirectMethod]
public string strA()
{
string str1 = "a-Value" + DateTime.Today.AddMonths(-1).ToString("yyyy-MM-dd");
return str1;
}

protected void Button1_Click(object sender, DirectEventArgs e)
{
UserControlLoader ul1 = X.GetCmp<UserControlLoader>("uc1");
ul1.Render(); //??? I dont know how to refresh
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET Examples</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:Panel
ID="Panel1"
runat="server"
Title="Panel"
Height="150"
Width ="280">
<Items>

<ext:Button runat="server" Text="Set DirectMethod-Value to txtB" OnDirectClick="Button1_Click" ID ="Button1"/>

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



b.ascx


<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<ext:TextField ID="txtb" runat="server" FieldLabel="txtB" LabelWidth="25" />

<script type="text/javascript">
var str2 = '';
//str2 = parent.App.direct.strA(); //// ??? I dont know how to get strA() from a.aspx
App.txtb.setValue(str2);
</script>

Daniil
Oct 09, 2014, 9:05 PM
Hi @CPA1158139,

You could do the following in the user control.

Example

<ext:TextField
ID="txtb"
runat="server"
FieldLabel="txtB"
LabelWidth="25">
<Listeners>
<Render Handler="var field = this;
App.direct.strA({
success: function(result) {
field.setValue(result);
}
});" />
</Listeners>
</ext:TextField>

As for refreshing a UserControlLoader, I would wrap it in an additional Container:

<ext:Container ID="Container1" runat="server" />

Container1.Items.Add(ul1);
and call

this.Container1.UpdateContent();

But it is not working. Probably, a defect in Ext.NET. We will try to fix.

As a solution you can do the following.

1. Place this into the Panel1's Items.

<ext:Container ID="Container1" runat="server" Layout="AnchorLayout" />

2. Use these methods:

protected void Page_Init(object sender, EventArgs e)
{
this.Container1.ContentControls.Add(this.LoadContr ol("TestUC.ascx"));
}

protected void Button1_Click(object sender, DirectEventArgs e)
{
this.Container1.UpdateContent();
}

CPA1158139
Oct 10, 2014, 2:35 AM
It works fine.Thanks very much!

Sorry, by the way,how to getValue without TextField? I get a error msg


b.ascx


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

<script type="text/javascript">
App.direct.strA({
success: function (result) {
alert(result);
}
});

</script>

Daniil
Oct 10, 2014, 9:05 AM
I get a error msg

Please always post the error and Exception messages.

I guess there is something like "App.direct is undefined".

It means that the script executes too early, before creating of the App.direct namespace.

You can use:

<script>
Ext.onReady(function() {
App.direct.strA({
success: function(result) {
alert(result);
}
});
});
</script>

CPA1158139
Oct 10, 2014, 3:59 PM
Sure,Daniil,you are great.
I understand Ext.onReady is used to initialize. How to render?

geoffrey.mcgill
Oct 10, 2014, 4:14 PM
How to render?

How to render what? Can you provide some more details, or an updated sample demonstrating the scenario you are attempting to get working.

CPA1158139
Oct 11, 2014, 4:03 AM
I understand there is a mistake. No problem.
pls close.
thanks very much.

Daniil
Oct 11, 2014, 7:43 AM
...and call

this.Container1.UpdateContent();
But it is not working. Probably, a defect in Ext.NET. We will try to fix.

It has been fixed in the revision #6021.