PDA

View Full Version : [CLOSED] How to change text of a label from code behind



feanor91
Oct 03, 2012, 1:20 PM
Hello

Perhaps the question is stupdid, but I have a lot of label into a window and I have to update their contens from code behind.

label.Text didn't work there is no setText function like in Ext.Js client side, so how can I do?

4876

all the 0 value must be filed and refresh all 2 minutes.

Daniil
Oct 03, 2012, 1:33 PM
Hi @feanor,

Setting the Label Text property should be enough.

Please provide a test case.

feanor91
Oct 03, 2012, 1:45 PM
Hi @feanor,

Setting the Label Text property should be enough.

Please provide a test case.

I was affraid you ask for...Just the time I made it, my label are code behind constructed, if it could help

feanor91
Oct 03, 2012, 2:29 PM
Here the example, sorry it is in VB because I made copy/paste from my code to be quick

It works exept the UpdateLabel function, I get nothing when I try to get the label.



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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<script runat="server">

Public Sub CreateZonesPanel()

Dim NbZones As Integer = 0
Dim ZoneName As String = ""
Dim XZone As Integer = 0
Dim YZone As Integer = 0
Dim HeightZone As Integer = 0
Dim WidthZone As Integer = 0
Dim myWindow As Ext.Net.Window = MyDesktop.Modules("Test").Window(0)


NbZones = 1

For i As Integer = 1 To NbZones

Dim MyZonePanel As New Ext.Net.Panel
Dim MyLblRed As New Ext.Net.Label
Dim MyLblYellow As New Ext.Net.Label
Dim MyLblGreen As New Ext.Net.Label
Dim MylabelSepar1 As New Ext.Net.Panel
Dim MylabelSepar2 As New Ext.Net.Panel

ZoneName = "toto"
XZone = 10
YZone = 10
HeightZone = 300
WidthZone = 500


Dim MyZonePanelHeader As New Ext.Net.PanelHeader
Dim MyZonePanelLayoutConfig As New Ext.Net.VBoxLayoutConfig

'MyZonePanelHeader.SetHeight(10)
MyZonePanelHeader.BaseCls = "x-panel-header-vm"
MyZonePanelLayoutConfig.Align = Ext.Net.VBoxAlign.Center
MyZonePanelLayoutConfig.Pack = Ext.Net.BoxPack.Center

MyZonePanel.ID = "pan" + i.ToString
MyZonePanel.TitleAlign = Ext.Net.TitleAlign.Center
MyZonePanel.Title = ZoneName
MyZonePanel.Layout = "VBoxLayout"
MyZonePanel.LayoutConfig.Add(MyZonePanelLayoutConf ig)
MyZonePanel.X = XZone
MyZonePanel.Y = YZone
MyZonePanel.Height = HeightZone
MyZonePanel.Width = WidthZone
MyZonePanel.BodyPadding = 5
MyZonePanel.Resizable = True
' MyZonePanel.Floating = True
MyZonePanel.Draggable = True
MyZonePanel.BodyCls = "x-panel-body-vm"
MyZonePanel.HeaderConfig = MyZonePanelHeader

MylabelSepar1.ID = "panSepar1" + i.ToString
MylabelSepar1.Height = 2
MylabelSepar1.Width = 10
MylabelSepar1.Border = False
MylabelSepar1.BodyCls = "x-panel-body-vm"

MylabelSepar2.ID = "panSepar2" + i.ToString
MylabelSepar2.Height = 2
MylabelSepar2.Width = 10
MylabelSepar2.Border = False
MylabelSepar2.BodyCls = "x-panel-body-vm"

MyLblRed.ID = "lblZone" + i.ToString + "Red"
MyLblRed.Text = "0"
MyLblRed.Width = WidthZone - 10
MyLblRed.BaseCls = "red-mov white"
MyLblRed.Border = 2

MyLblYellow.ID = "lblZone" + i.ToString + "Yellow"
MyLblYellow.Text = "0"
MyLblYellow.Width = WidthZone - 10
MyLblYellow.BaseCls = "yellow white"
MyLblYellow.Border = 2

MyLblGreen.ID = "lblZone" + i.ToString + "Green"
MyLblGreen.Text = "0"
MyLblGreen.Width = WidthZone - 10
MyLblGreen.BaseCls = "green white"
MyLblGreen.Border = 2

MyZonePanel.Items.Add(MyLblRed)
MyZonePanel.Items.Add(MylabelSepar1)
MyZonePanel.Items.Add(MyLblYellow)
MyZonePanel.Items.Add(MylabelSepar2)
MyZonePanel.Items.Add(MyLblGreen)

MyZonePanel.Render(myWindow)

Next


End Sub

Public Sub UpdateLabel()
lblTest.Text = "Test to change fixed label"
'CType(Page.FindControl("lblZone1Green"), Ext.Net.Label).Text = "Test to change"
End Sub

</script>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.white
{
text-align:center;
color : #FFFFFF;
}
.red
{
text-align:center;
background-color:red;
background-repeat:repeat;
}
.red-mov
{
text-align:center;
background-image:url(images/red-carre.gif);
background-repeat:repeat;
font-weight:bold;
}
.yellow
{
text-align:center;
background-color : #FF4300;
font-weight:bold;
}
.green
{
text-align:center;
background-color : #007F0E;
font-weight:bold;
}
.graylabel
{
text-align:center;
background-color: #C9CBE2;
font-weight:bold;
color : #000000 !important;
}
</style>
</head>

<body>
<form id="form1" runat="server">

<ext:ResourceManager ID="ResourceManager" runat="server" RethrowAjaxExceptions="True">
</ext:ResourceManager>

<ext:Desktop ID="MyDesktop" runat="server">

<Modules>
<%-- Test window--%>
<ext:DesktopModule ModuleID="Test" AutoRun="True">
<Window>
<ext:Window
ID="wndTest"
runat="server"
Width="630"
Height="910"
ExpandOnShow="True"
TitleCollapse="false"
Collapsible="false"
Layout="AbsoluteLayout"
Maximizable="false"
Minimizable="False"
Closable="true"
Title="Test"
TitleAlign="Center"
X="1"
y="1">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="Create Panel">
<DirectEvents>
<Click OnEvent="CreateZonesPanel"></Click>
</DirectEvents>
</ext:Button>
<ext:Button ID="Button1" runat="server" Text="set label text">
<DirectEvents>
<Click OnEvent="UpdateLabel"></Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Items>
<ext:Label runat="server" ID="lblTest" Text="Label to test"></ext:Label>
</Items>
</ext:Window>
</Window>
</ext:DesktopModule>
</Modules>

</ext:Desktop>

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



Edit 1: Just a little detail, but depending the value in label I have to change the CSS too.

Edit 2: I change code to add a label directly in the items of the window, and it works, so the problem is to get the code behind created label after they were created.

geoffrey.mcgill
Oct 03, 2012, 3:26 PM
Your UpdateLabel Method needs to be configured as a DirectEvent event handler. The Method signature should look like the following:

Example


<script runat="server">
protected void UpdateLabel(object sender, DirectEventArgs e)
{
this.lblTest.Text = "Test to change fixed label";
}
</script>


There are lots of examples of how to configure a DirectEvent in the Examples Explorer.

http://examples2.ext.net/#/Events/DirectEvents/Overview/

Hope this helps.

Daniil
Oct 03, 2012, 8:08 PM
Yes, please follow the Geoffrey's recommendation.

Though, I discovered that your handler is somehow triggered. I would bet it should not. Probably, some VB.NET trick.

Regarding this:

CType(Page.FindControl("lblZone1Green"), Ext.Net.Label).Text = "Test to change"

You create the Label in one request, but try to find this Label in another request. But it is not created. ASP.NET doesn't recreates controls automatically, it is a stateless system.

We can suggest to use the X.GetCmp.

Example C#

var label = X.GetCmp<Ext.Net.Label>("labelCliendId");
label.Text = "new text";

Some X.GetCmp details are here:
http://forums.ext.net/showthread.php?10578&p=42517&viewfull=1#post42517

feanor91
Oct 04, 2012, 7:16 AM
Hello

I just applied both recomandation, but still didn't work:



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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<script runat="server">

Public Sub CreateZonesPanel()

Dim NbZones As Integer = 0
Dim ZoneName As String = ""
Dim XZone As Integer = 0
Dim YZone As Integer = 0
Dim HeightZone As Integer = 0
Dim WidthZone As Integer = 0
Dim myWindow As Ext.Net.Window = MyDesktop.Modules("Test").Window(0)


NbZones = 1

For i As Integer = 1 To NbZones

Dim MyZonePanel As New Ext.Net.Panel
Dim MyLblRed As New Ext.Net.Label
Dim MyLblYellow As New Ext.Net.Label
Dim MyLblGreen As New Ext.Net.Label
Dim MylabelSepar1 As New Ext.Net.Panel
Dim MylabelSepar2 As New Ext.Net.Panel

ZoneName = "toto"
XZone = 10
YZone = 10
HeightZone = 300
WidthZone = 500


Dim MyZonePanelHeader As New Ext.Net.PanelHeader
Dim MyZonePanelLayoutConfig As New Ext.Net.VBoxLayoutConfig

'MyZonePanelHeader.SetHeight(10)
MyZonePanelHeader.BaseCls = "x-panel-header-vm"
MyZonePanelLayoutConfig.Align = Ext.Net.VBoxAlign.Center
MyZonePanelLayoutConfig.Pack = Ext.Net.BoxPack.Center

MyZonePanel.ID = "pan" + i.ToString
MyZonePanel.TitleAlign = Ext.Net.TitleAlign.Center
MyZonePanel.Title = ZoneName
MyZonePanel.Layout = "VBoxLayout"
MyZonePanel.LayoutConfig.Add(MyZonePanelLayoutConf ig)
MyZonePanel.X = XZone
MyZonePanel.Y = YZone
MyZonePanel.Height = HeightZone
MyZonePanel.Width = WidthZone
MyZonePanel.BodyPadding = 5
MyZonePanel.Resizable = True
' MyZonePanel.Floating = True
MyZonePanel.Draggable = True
MyZonePanel.BodyCls = "x-panel-body-vm"
MyZonePanel.HeaderConfig = MyZonePanelHeader

MylabelSepar1.ID = "panSepar1" + i.ToString
MylabelSepar1.Height = 2
MylabelSepar1.Width = 10
MylabelSepar1.Border = False
MylabelSepar1.BodyCls = "x-panel-body-vm"

MylabelSepar2.ID = "panSepar2" + i.ToString
MylabelSepar2.Height = 2
MylabelSepar2.Width = 10
MylabelSepar2.Border = False
MylabelSepar2.BodyCls = "x-panel-body-vm"

MyLblRed.ID = "lblZone" + i.ToString + "Red"
MyLblRed.Text = "0"
MyLblRed.Width = WidthZone - 10
MyLblRed.BaseCls = "red-mov white"
MyLblRed.Border = 2

MyLblYellow.ID = "lblZone" + i.ToString + "Yellow"
MyLblYellow.Text = "0"
MyLblYellow.Width = WidthZone - 10
MyLblYellow.BaseCls = "yellow white"
MyLblYellow.Border = 2

MyLblGreen.ID = "lblZone" + i.ToString + "Green"
MyLblGreen.Text = "0"
MyLblGreen.Width = WidthZone - 10
MyLblGreen.BaseCls = "green white"
MyLblGreen.Border = 2

MyZonePanel.Items.Add(MyLblRed)
MyZonePanel.Items.Add(MylabelSepar1)
MyZonePanel.Items.Add(MyLblYellow)
MyZonePanel.Items.Add(MylabelSepar2)
MyZonePanel.Items.Add(MyLblGreen)

MyZonePanel.Render(myWindow)

Next


End Sub

Public Sub UpdateLabel(ByVal sender As Object, ByVal e As DirectEventArgs)
Dim lbl As Ext.Net.Label

lblTest.Text = "Test to change fixed label"
lbl = Ext.Net.X.GetCmp("lblZone1Green")
lbl.Text = "Test lable text"

End Sub

</script>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.white
{
text-align:center;
color : #FFFFFF;
}
.red
{
text-align:center;
background-color:red;
background-repeat:repeat;
}
.red-mov
{
text-align:center;
background-image:url(images/red-carre.gif);
background-repeat:repeat;
font-weight:bold;
}
.yellow
{
text-align:center;
background-color : #FF4300;
font-weight:bold;
}
.green
{
text-align:center;
background-color : #007F0E;
font-weight:bold;
}
.graylabel
{
text-align:center;
background-color: #C9CBE2;
font-weight:bold;
color : #000000 !important;
}
</style>
</head>

<body>
<form id="form1" runat="server">

<ext:ResourceManager ID="ResourceManager" runat="server" RethrowAjaxExceptions="True">
</ext:ResourceManager>

<ext:Desktop ID="MyDesktop" runat="server">

<Modules>
<%-- Test window--%>
<ext:DesktopModule ModuleID="Test" AutoRun="True">
<Window>
<ext:Window
ID="wndTest"
runat="server"
Width="630"
Height="910"
ExpandOnShow="True"
TitleCollapse="false"
Collapsible="false"
Layout="AbsoluteLayout"
Maximizable="false"
Minimizable="False"
Closable="true"
Title="Test"
TitleAlign="Center"
X="1"
y="1">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="Create Panel">
<DirectEvents>
<Click OnEvent="CreateZonesPanel"></Click>
</DirectEvents>
</ext:Button>
<ext:Button ID="Button1" runat="server" Text="set label text">
<DirectEvents>
<Click OnEvent="UpdateLabel"></Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Items>
<ext:Label runat="server" ID="lblTest" Text="Label to test"></ext:Label>
</Items>
</ext:Window>
</Window>
</ext:DesktopModule>
</Modules>

</ext:Desktop>

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


lbl after get cmp is set to nothing.

feanor91
Oct 04, 2012, 7:22 AM
I change some things:



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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<script runat="server">

Public Sub CreateZonesPanel()

Dim NbZones As Integer = 0
Dim ZoneName As String = ""
Dim XZone As Integer = 0
Dim YZone As Integer = 0
Dim HeightZone As Integer = 0
Dim WidthZone As Integer = 0
Dim myWindow As Ext.Net.Window = MyDesktop.Modules("Test").Window(0)


NbZones = 1

For i As Integer = 1 To NbZones

Dim MyZonePanel As New Ext.Net.Panel
Dim MyLblRed As New Ext.Net.Label
Dim MyLblYellow As New Ext.Net.Label
Dim MyLblGreen As New Ext.Net.Label
Dim MylabelSepar1 As New Ext.Net.Panel
Dim MylabelSepar2 As New Ext.Net.Panel
Dim lstLabel As List(Of Ext.Net.Label) = New List(Of Ext.Net.Label)
ZoneName = "toto"
XZone = 10
YZone = 10
HeightZone = 300
WidthZone = 500


Dim MyZonePanelHeader As New Ext.Net.PanelHeader
Dim MyZonePanelLayoutConfig As New Ext.Net.VBoxLayoutConfig

'MyZonePanelHeader.SetHeight(10)
MyZonePanelHeader.BaseCls = "x-panel-header-vm"
MyZonePanelLayoutConfig.Align = Ext.Net.VBoxAlign.Center
MyZonePanelLayoutConfig.Pack = Ext.Net.BoxPack.Center

MyZonePanel.ID = "pan" + i.ToString
MyZonePanel.TitleAlign = Ext.Net.TitleAlign.Center
MyZonePanel.Title = ZoneName
MyZonePanel.Layout = "VBoxLayout"
MyZonePanel.LayoutConfig.Add(MyZonePanelLayoutConf ig)
MyZonePanel.X = XZone
MyZonePanel.Y = YZone
MyZonePanel.Height = HeightZone
MyZonePanel.Width = WidthZone
MyZonePanel.BodyPadding = 5
MyZonePanel.Resizable = True
' MyZonePanel.Floating = True
MyZonePanel.Draggable = True
MyZonePanel.BodyCls = "x-panel-body-vm"
MyZonePanel.HeaderConfig = MyZonePanelHeader

MylabelSepar1.ID = "panSepar1" + i.ToString
MylabelSepar1.Height = 2
MylabelSepar1.Width = 10
MylabelSepar1.Border = False
MylabelSepar1.BodyCls = "x-panel-body-vm"

MylabelSepar2.ID = "panSepar2" + i.ToString
MylabelSepar2.Height = 2
MylabelSepar2.Width = 10
MylabelSepar2.Border = False
MylabelSepar2.BodyCls = "x-panel-body-vm"

MyLblRed.ID = "lblZone" + i.ToString + "Red"
MyLblRed.Text = "0"
MyLblRed.Width = WidthZone - 10
MyLblRed.BaseCls = "red-mov white"
MyLblRed.Border = 2

MyLblYellow.ID = "lblZone" + i.ToString + "Yellow"
MyLblYellow.Text = "0"
MyLblYellow.Width = WidthZone - 10
MyLblYellow.BaseCls = "yellow white"
MyLblYellow.Border = 2

MyLblGreen.ID = "lblZone" + i.ToString + "Green"
MyLblGreen.Text = "0"
MyLblGreen.Width = WidthZone - 10
MyLblGreen.BaseCls = "green white"
MyLblGreen.Border = 2
lstLabel.Add(MyLblGreen)

MyZonePanel.Items.Add(MyLblRed)
MyZonePanel.Items.Add(MylabelSepar1)
MyZonePanel.Items.Add(MyLblYellow)
MyZonePanel.Items.Add(MylabelSepar2)
MyZonePanel.Items.Add(MyLblGreen)

MyZonePanel.Render(myWindow)

Session("Label") = lstLabel

Next


End Sub

Public Sub UpdateLabel(ByVal sender As Object, ByVal e As DirectEventArgs)
Dim lbl As New Ext.Net.Label
Dim lstLabel As List(Of Ext.Net.Label) = New List(Of Ext.Net.Label)
lstLabel = Session("Label")

lblTest.Text = "Test to change fixed label"
lbl = Ext.Net.X.GetCmp("lblZone1Green")
'lbl.Text = "Test lable text"

lstLabel(0).Text = "Test to change fixed label"
'CType(Page.FindControl("lblZone1Green"), Ext.Net.Label).Text = "Test to change"
End Sub

</script>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.white
{
text-align:center;
color : #FFFFFF;
}
.red
{
text-align:center;
background-color:red;
background-repeat:repeat;
}
.red-mov
{
text-align:center;
background-image:url(images/red-carre.gif);
background-repeat:repeat;
font-weight:bold;
}
.yellow
{
text-align:center;
background-color : #FF4300;
font-weight:bold;
}
.green
{
text-align:center;
background-color : #007F0E;
font-weight:bold;
}
.graylabel
{
text-align:center;
background-color: #C9CBE2;
font-weight:bold;
color : #000000 !important;
}
</style>
</head>

<body>
<form id="form1" runat="server">

<ext:ResourceManager ID="ResourceManager" runat="server" RethrowAjaxExceptions="True">
</ext:ResourceManager>

<ext:Desktop ID="MyDesktop" runat="server">

<Modules>
<%-- Test window--%>
<ext:DesktopModule ModuleID="Test" AutoRun="True">
<Window>
<ext:Window
ID="wndTest"
runat="server"
Width="630"
Height="910"
ExpandOnShow="True"
TitleCollapse="false"
Collapsible="false"
Layout="AbsoluteLayout"
Maximizable="false"
Minimizable="False"
Closable="true"
Title="Test"
TitleAlign="Center"
X="1"
y="1">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="Create Panel">
<DirectEvents>
<Click OnEvent="CreateZonesPanel"></Click>
</DirectEvents>
</ext:Button>
<ext:Button ID="Button1" runat="server" Text="set label text">
<DirectEvents>
<Click OnEvent="UpdateLabel"></Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Items>
<ext:Label runat="server" ID="lblTest" Text="Label to test"></ext:Label>
</Items>
</ext:Window>
</Window>
</ext:DesktopModule>
</Modules>

</ext:Desktop>

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


I save my label into a session and reload it when I want to change text. On debug, we can see the text is changed in stored label but it is not updated in the page like if I mus do a refresh or something like that.

geoffrey.mcgill
Oct 04, 2012, 7:58 AM
Is there any particular reason why this code sample needs to be >200 lines of code? Can you simplify? This seems like a problem that can be reproduced in <50 lines or less of code.

feanor91
Oct 04, 2012, 8:11 AM
You didn't like big code? ;)

By the way, you'r right, so I remove all not necessary things, I don't think I can remove more:



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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<script runat="server">

Public Sub CreateZonesPanel()
Dim myWindow As Ext.Net.Window = MyDesktop.Modules("Test").Window(0)

Dim MyZonePanel As New Ext.Net.Panel
Dim MyLblGreen As New Ext.Net.Label
Dim lstLabel As List(Of Ext.Net.Label) = New List(Of Ext.Net.Label)

Dim MyZonePanelLayoutConfig As New Ext.Net.VBoxLayoutConfig

MyZonePanelLayoutConfig.Align = Ext.Net.VBoxAlign.Center
MyZonePanelLayoutConfig.Pack = Ext.Net.BoxPack.Center

MyZonePanel.ID = "pan1"
MyZonePanel.TitleAlign = Ext.Net.TitleAlign.Center
MyZonePanel.Title = "Test panel"
MyZonePanel.Layout = "VBoxLayout"
MyZonePanel.LayoutConfig.Add(MyZonePanelLayoutConf ig)
MyZonePanel.X = 10
MyZonePanel.Y = 20
MyZonePanel.Height = 300
MyZonePanel.Width = 500

MyLblGreen.ID = "lblZone1Green"
MyLblGreen.Text = "0"
MyLblGreen.Width = 400
MyLblGreen.BaseCls = "green white"
MyLblGreen.Border = 2
lstLabel.Add(MyLblGreen)

MyZonePanel.Items.Add(MyLblGreen)

MyZonePanel.Render(myWindow)

Session("Label") = lstLabel
End Sub

Public Sub UpdateLabel(ByVal sender As Object, ByVal e As DirectEventArgs)
Dim lbl As Ext.Net.Label
Dim lstLabel As List(Of Ext.Net.Label) = New List(Of Ext.Net.Label)
lstLabel = Session("Label")

lblTest.Text = "Test to change fixed label"
lbl = Ext.Net.X.GetCmp("lblZone1Green")
'lbl.Text = "Test lable text"

lstLabel(0).Text = "Test to change fixed label"
'CType(Page.FindControl("lblZone1Green"), Ext.Net.Label).Text = "Test to change"
End Sub

</script>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.white
{
text-align:center;
color : #FFFFFF;
}
.green
{
text-align:center;
background-color : #007F0E;
font-weight:bold;
}
</style>
</head>

<body>
<form id="form1" runat="server">

<ext:ResourceManager ID="ResourceManager" runat="server" RethrowAjaxExceptions="True">
</ext:ResourceManager>

<ext:Desktop ID="MyDesktop" runat="server">

<Modules>
<%-- Test window--%>
<ext:DesktopModule ModuleID="Test" AutoRun="True">
<Window>
<ext:Window
ID="wndTest"
runat="server"
Width="630"
Height="910"
ExpandOnShow="True"
Layout="AbsoluteLayout"
Title="Test"
TitleAlign="Center">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="Create Panel">
<DirectEvents>
<Click OnEvent="CreateZonesPanel"></Click>
</DirectEvents>
</ext:Button>
<ext:Button ID="Button1" runat="server" Text="set label text">
<DirectEvents>
<Click OnEvent="UpdateLabel"></Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Items>
<ext:Label runat="server" ID="lblTest" Text="Label to test"></ext:Label>
</Items>
</ext:Window>
</Window>
</ext:DesktopModule>
</Modules>

</ext:Desktop>

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


I try from javascript with the setText function and it works well, so I have a "plan B" if there is no solution from codebehind.

Daniil
Oct 04, 2012, 8:32 AM
Thank you for simplifying the code sample.


You didn't like big code? ;)

Well, we do like. Ext.NET is big and we like it:)

Just posting only required code to reproduce the problem saves your and our time.

Our time because we can immediately focus on a problem if a sample is simplified.

Your time because it gives you a best chance to get a solution as soon as possible.

The formula is simple: shortest code => quickest solution/turnaround.

Now, regarding the problem.

This appears to be working fine with your code sample.



We can suggest to use the X.GetCmp.

Example C#

var label = X.GetCmp<Ext.Net.Label>("labelCliendId");
label.Text = "new text";

Some X.GetCmp details are here:
http://forums.ext.net/showthread.php?10578&p=42517&viewfull=1#post42517

You have to use a generic version of X.GetCmp as I demonstrated.

Example VB.NET

lbl = Ext.Net.X.GetCmp(Of Ext.Net.Label)("lblZone1Green")
lbl.Text = "Test lable text"

Also please note that saving controls is Session is a very poor practice. I would recommend to avoid it.

feanor91
Oct 04, 2012, 9:13 AM
Yes your right for size of code.

So it works, except I need to do that:



Public Sub UpdateLabel(ByVal sender As Object, ByVal e As DirectEventArgs)

Dim lbl = Ext.Net.X.GetCmp(Of Ext.Net.Label)("lblZone1Green")
lbl.Text = CInt(lbl.Text) + 1

End Sub

and here, lbl.text is not 0 as expected but "" and if I put 5 for example at label creation, it's still "" in UpdateLabel.

Daniil
Oct 04, 2012, 9:24 AM
If you will follow the link I posted, you would know that it loads a data from POST. Labels doesn't submit its text in POST, they are not submittable.

You can use the Label Append, AppendLine methods.

feanor91
Oct 04, 2012, 9:39 AM
OK, I undesrtand.

I have use another way to compute values, I have to refine it but basically it works. Thanks for help.

geoffrey.mcgill
Oct 04, 2012, 9:43 AM
The Label.Text value is NOT persisted across requests. If you want to persist a value across requests, you can try putting something in the Session, or better yet, placing the value into a Hidden Field.

Hope this helps.

geoffrey.mcgill
Oct 04, 2012, 10:02 AM
By the way, you'r right, so I remove all not necessary things, I don't think I can remove more:

You can always remove more. And in future forum posts, I encourage you to reduce your samples down to the absolute minimum required to reproduce the issue.

I was able to reduce your sample down to 35 lines of code, retain proper source formatting, and it still reproduces your issue.

Please try harder next time, because unfortunately we're not going to put this much work into issues next time. Clearly and simply demonstrate the problem in the first post, or the thread will have to go unanswered by the Support Teams.

Example


<%@ Page Language="C#" %>
<!DOCTYPE html>

<script runat="server">
public void Button1_Click(object sender, DirectEventArgs e)
{
var label = new Ext.Net.Label {
ID = "Label1",
Text = "0"
};


label.AddTo(this.Panel1);
}

public void Button2_Click(object sender, DirectEventArgs e)
{
var label = X.GetCmp("Label1");
}
</script>

<html>
<head runat="server">
<title>Ext.NET Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:Panel ID="Panel1" runat="server" Title="Example" />
<ext:Button runat="server" Text="Create Label" OnDirectClick="Button1_Click" />
<ext:Button runat="server" Text="Set Text" OnDirectClick="Button2_Click" />
</form>
</body>
</html>

feanor91
Oct 04, 2012, 2:42 PM
I start from your exemple, because I have another problem to update label content that works in your example and not in mine.

So in your example you have :


label.AddTo(this.Panel1);

In my I have:


this.Panel1.Items.Add(label);

With your code, the panel is created with the label in it, in my example not.

If I put AddTo in place of .Add in my code nothing is created

So what the difference between the 2 examples, except in my code I need to put panel into a window?

The modifications:



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

<!DOCTYPE html>

<script runat="server">
public void Button1_Click(object sender, DirectEventArgs e)
{
var label = new Ext.Net.Label {
ID = "Label1",
Text = "0"
};


//label.AddTo(this.Panel1);
this.Panel1.Items.Add(label);
//Test();
}

public void Button2_Click(object sender, DirectEventArgs e)
{
var label = X.GetCmp < Ext.Net.Label > ("Label1");
label.Text = "ttiti";
}

public void Test()
{
var label = X.GetCmp<Ext.Net.Label>("Label1");
label.Text = "toto";
}
</script>

<html>
<head id="Head1" runat="server">
<title>Ext.NET Example</title>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />

<ext:Panel ID="Panel1" runat="server" Title="Example" />
<ext:Button ID="Button1" runat="server" Text="Create Label" OnDirectClick="Button1_Click" />
<ext:Button ID="Button2" runat="server" Text="Set Text" OnDirectClick="Button2_Click" />
</form>
</body>
</html>

Daniil
Oct 04, 2012, 3:23 PM
If you put the Label into the Items, then you should call Render for this Label.

label.Render();

Just putting to Items doesn't render the control.

But, I think, it is another issue which doesn't meet the thread title.

The initial issue appears to be resolved. Can you confirm?

feanor91
Oct 04, 2012, 4:26 PM
In fact, this is the following of the issue.

I need to
1-Create x panels and adding 3 labels to each panel --> done
2-showing those panels in a window --> done
3-updaing panel with their value after their creation -->almost done.

It works well if I update from a button of the window, when all labels are rendered, but not just after there creation. The most strange is that after creation, I manage to change label color with CSS depending I have 0 value (gray label) or positive value (red, yellow or green depending importance of the label), but the text in all label is 0. When I click on the button I put to update them it woks, so the update function works. I think it is something related to the window not yet rendered or something like that, because if I try the same thing in you'r example and it works. The 2 differences are you'r label is not into a window and you use AddTo in place of .add, as far as I could see (so be it the importance of the most close context in example).

Tomorrow, I will try to call the update function from an event of the window when it is rendered.

Daniil
Oct 04, 2012, 5:14 PM
Thank you for the details. However, it is too difficult to predict what can be wrong there.

If you would provide a sample, we will do our best to investigate.

feanor91
Oct 05, 2012, 7:28 AM
All it's done, I call my function to update data on the show event of the window and it works. You could close thread.

Thanks.