Hello,
I'm just sticking with a problem regarding the viewstate of a RadButton.
I want to create a RadButton dynamically and use it then further on. This given, I have two szenarios:
1. I create a RadButton and check it with the mouse. On the following PostBack, everything is OK and the checked- property has the expeted value.
2. I create a RadButton and check it during creation. If I don't change the state in the frontend, then the checked- property is alsways false, not matter, what I set it to.
The shown value of the RadButton is always correct, until the mysterious PostBack. If I try to produce the behaviour with the ASP:CheckBox, everything works fine.
Has somebody a hint, what my mistake is?
Yours Aljoscha
Here is my example code to reproduce:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>
<!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"
>
<
title
></
title
>
<
telerik:RadStyleSheetManager
ID
=
"RadStyleSheetManager1"
runat
=
"server"
/>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
<
Scripts
>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI"
Name
=
"Telerik.Web.UI.Common.Core.js"
/>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI"
Name
=
"Telerik.Web.UI.Common.jQuery.js"
/>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI"
Name
=
"Telerik.Web.UI.Common.jQueryInclude.js"
/>
</
Scripts
>
</
telerik:RadScriptManager
>
<
div
id
=
"myDiv"
runat
=
"server"
>
<
telerik:RadButton
runat
=
"server"
OnClick
=
"Unnamed_Click"
></
telerik:RadButton
>
<
asp:Label
runat
=
"server"
ID
=
"lbText"
></
asp:Label
>
</
div
>
</
form
>
</
body
>
</
html
>
protected
void
Page_Load(
object
sender, EventArgs e)
{
RadButton rb = (RadButton)LoadControl(
typeof
(RadButton),
new
object
[0]);
// RadButton rb = new RadButton();
rb.ID =
"Test1234"
;
rb.ButtonType = RadButtonType.ToggleButton;
rb.ToggleType = ButtonToggleType.CheckBox;
rb.Text =
"Testcheck RadButton"
;
rb.AutoPostBack =
false
;
CheckBox cb =
new
CheckBox();
cb.ID =
"Test3456"
;
cb.Text =
"Testcheck CheckBox"
;
cb.AutoPostBack =
false
;
if
(!IsPostBack)
{
rb.Checked =
true
;
cb.Checked =
true
;
}
myDiv.Controls.Add(rb);
myDiv.Controls.Add(cb);
}
protected
void
Unnamed_Click(
object
sender, EventArgs e)
{
foreach
(Control ctrl
in
myDiv.Controls)
{
if
(ctrl
is
RadButton)
{
RadButton rb = ctrl
as
RadButton;
lbText.Text +=
"RadButton "
+ rb.ID +
" : "
+ rb.Checked.ToString() +
"<br/>\r\n"
;
}
if
(ctrl
is
CheckBox)
{
CheckBox cb = ctrl
as
CheckBox;
lbText.Text +=
"CheckBox "
+ cb.ID +
" : "
+ cb.Checked.ToString() +
"<br/>\r\n"
;
}
}
}