Aug 21, 2011, 10:39 AM
Bug with dynamic panels and slider control
Hello All,
I think that i found another bug ( or two may be ) with my current project.
I'm using only dynamic creation of controls, so may be this is not usual task and i found some problems.
Currently i will show bug with siled panel. When i create panel dynamicaly, and add to this panel slider control,
during post backs, control dont have propper value.
Here is a code :
File : Default.aspx
Then moving of slider cause execution of direct event handler AudioSliderValueChange. In this function we read value
of slider control and show this value in fldValue control, plus we add timestamp when value is updated.
As you can see - moving of slider doesent affect of control value.
I think that its important to say, if Panel2 is created first , all works ok. But if we create first panel1 , and then
create Panel 2 with clicking of button - control not work on propper way.
This also can be reproduced easy - start application, click on button Panel 2, then stop and start again application from Visual Studio.
Then Panel 2 first will be displayed. Moving of slider works ok.
This is a one think. Another that i see is that in constructor of class PanelType2, i have code for putting of timestamp
in title :
I found another bug with grid panels, but will put in separate thread :)
Regards,
Nedelcho
I think that i found another bug ( or two may be ) with my current project.
I'm using only dynamic creation of controls, so may be this is not usual task and i found some problems.
Currently i will show bug with siled panel. When i create panel dynamicaly, and add to this panel slider control,
during post backs, control dont have propper value.
Here is a code :
File : Default.aspx
%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server" ID="resman" DirectMethodNamespace="DM"/>
<ext:Viewport runat="server" ID="id_viewport">
<Items>
<ext:Panel runat="server">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" ID="Button1" Text="Panel 1"></ext:Button>
<ext:Button runat="server" ID="Button2" Text="Panel 2"></ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Items>
<ext:Panel runat="server" id="id_container" Title="Main panel" >
</ext:Panel>
</Items>
</ext:Panel>
</Items>
</ext:Viewport>
</form>
</body>
</html>
File : Default.aspx.csusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
namespace WebApplication2
{
public class PanelType1 : Ext.Net.Panel
{
public PanelType1()
{
this.ID = "id_paneltype_1";
this.Height = 600;
this.Layout = "Absolute";
this.Title = "Panel Type 1" + " ( Updated on " + DateTime.Now + " )";
this.Html = "Panel from type 1";
}
}
public class PanelType2 : Ext.Net.Panel
{
Ext.Net.Slider sldAudioOff;
Ext.Net.TextField fldValue;
Ext.Net.Label fldUpdateTime;
Ext.Net.Label fldLabel;
public PanelType2()
{
this.ID = "id_paneltype_2";
this.Title = "Panel Type 2" + " ( Updated on " + DateTime.Now + " )";
this.Height = 600;
this.Layout = "Absolute";
sldAudioOff = new Ext.Net.Slider { ID = "id_audioSlide", X = 5, Y = 10, Width = 200, MinValue = -10, MaxValue = 10, Value = 0 };
fldLabel = new Ext.Net.Label { ID = "id_val_label1", X = 215, Y = 10, Text = "Value of slider" };
fldValue = new Ext.Net.TextField { ID = "id_text_fld" , X = 310, Y = 10, Width = 40, Text = sldAudioOff.Value.ToString() };
fldUpdateTime = new Ext.Net.Label { ID = "id_val_label2", X = 360, Y = 10, Text = "" };
sldAudioOff.DirectEvents.ChangeComplete.Event += this.AudioSliderValueChange;
this.Add(sldAudioOff);
this.Add(fldLabel);
this.Add(fldValue);
this.Add(fldUpdateTime);
}
public void AudioSliderValueChange(object sender, DirectEventArgs args)
{
fldValue.Text = sldAudioOff.Value.ToString();
fldUpdateTime.Text = "Updated on " + DateTime.Now;
}
}
public partial class _Default : System.Web.UI.Page
{
public static int showtype=1;
protected override void OnInit(EventArgs e)
{
Button1.DirectEvents.Click.Event += AddNewPanel_1;
Button2.DirectEvents.Click.Event += AddNewPanel_2;
AddPanel(false);
base.OnInit(e);
}
protected void RemoveCurrentPanel()
{
Ext.Net.Panel p1 = (Ext.Net.Panel)id_container.Items[0];
id_container.Remove(p1, true);
id_container.DoLayout();
}
protected void AddNewPanel_1(object sender, DirectEventArgs e)
{
showtype = 1;
RemoveCurrentPanel();
AddPanel();
}
protected void AddNewPanel_2(object sender, DirectEventArgs e)
{
showtype = 2;
RemoveCurrentPanel();
AddPanel();
}
public void AddPanel(bool DoRendering = true)
{
if (showtype == 1)
{
PanelType1 panel = new PanelType1();
id_container.Items.Add(panel);
if (DoRendering)
panel.Render();
}
else if (showtype == 2)
{
PanelType2 panel = new PanelType2();
id_container.Items.Add(panel);
if (DoRendering)
panel.Render();
}
id_container.DoLayout();
}
}
}
Bug can be reproduced in this way : when app stars, click on button "Panel 2". Second panel will be displayed.Then moving of slider cause execution of direct event handler AudioSliderValueChange. In this function we read value
of slider control and show this value in fldValue control, plus we add timestamp when value is updated.
As you can see - moving of slider doesent affect of control value.
I think that its important to say, if Panel2 is created first , all works ok. But if we create first panel1 , and then
create Panel 2 with clicking of button - control not work on propper way.
This also can be reproduced easy - start application, click on button Panel 2, then stop and start again application from Visual Studio.
Then Panel 2 first will be displayed. Moving of slider works ok.
This is a one think. Another that i see is that in constructor of class PanelType2, i have code for putting of timestamp
in title :
this.Title = "Panel Type 2" + " ( Updated on " + DateTime.Now + " )";
Problem is that, even we pass trough constructor, title of pannel is not changed.I found another bug with grid panels, but will put in separate thread :)
Regards,
Nedelcho