G
Gellert
Hello,
I am trying to create a server control with some radiobuttons (will be
a survey control).
If a radiobutton is clicked (SelectedChanged) then the attribute
"selectedValue" should be set to the id of the radiobutton.... so far,
there is no problem..... but when i press the submit button at the end
of my aspx the set attribute in my control class is not there....
here is the code of my class:
------------------------------------------------------
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CompositionSampleControls
{
public class Composition3 : Control, INamingContainer
{
private String selectedvalue;
public int Value
{
get
{
this.EnsureChildControls();
return Int32.Parse(((TextBox)Controls[3]).Text);
}
set
{
this.EnsureChildControls();
((TextBox)Controls[3]).Text = value.ToString();
}
}
public virtual String SelectedValue
{
get
{
this.EnsureChildControls();
return selectedvalue;
}
set
{
this.EnsureChildControls();
selectedvalue = value.ToString();
}
}
protected override void CreateChildControls()
{
Label LeftHandLabel = new Label();
LeftHandLabel.Text = LeftHandText;
this.Controls.Add(LeftHandLabel);
this.Controls.Add(new LiteralControl("     "));
for (int i = 1; i <= NumberOfRadio; i++)
{
RadioButton myRadio = new RadioButton();
myRadio.AutoPostBack = true;
myRadio.ID = (Convert.ToString(i));
myRadio.GroupName = "klaus";
myRadio.CheckedChanged += new
EventHandler(this.RadioButton_CheckedChanged);
this.Controls.Add(myRadio);
}
this.Controls.Add(new LiteralControl("</h3>"));
}
private void RadioButton_CheckedChanged(Object sender,
EventArgs e)
{
if (((RadioButton)sender).Checked)
{
this.SelectedValue = ((RadioButton)sender).ID;
this.Controls.Add(new
LiteralControl(this.selectedvalue));
}
}
}
}
--------------------------------
and the code an my aspx:
----------------------------------
protected void Button1_Click2(object sender, EventArgs e)
{
Response.Write("Eins:" + Composition3_1.SelectedValue+ "<br>");
Response.Write("Zwei " + Composition3_2.SelectedValue);
}
-------------------------------
The problem again: I do not get an value when I call
Composition3_1.SelectedValue. But I should get one, because my class
sets the value, when I click on a radiobutton.
Perhaps you have an idea.
Perhaps I lose the changes in my object (myobject.selectedvalue) when I
click the button on my aspx (postback problem?).
Thanks a lot.
Gellert
I am trying to create a server control with some radiobuttons (will be
a survey control).
If a radiobutton is clicked (SelectedChanged) then the attribute
"selectedValue" should be set to the id of the radiobutton.... so far,
there is no problem..... but when i press the submit button at the end
of my aspx the set attribute in my control class is not there....
here is the code of my class:
------------------------------------------------------
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CompositionSampleControls
{
public class Composition3 : Control, INamingContainer
{
private String selectedvalue;
public int Value
{
get
{
this.EnsureChildControls();
return Int32.Parse(((TextBox)Controls[3]).Text);
}
set
{
this.EnsureChildControls();
((TextBox)Controls[3]).Text = value.ToString();
}
}
public virtual String SelectedValue
{
get
{
this.EnsureChildControls();
return selectedvalue;
}
set
{
this.EnsureChildControls();
selectedvalue = value.ToString();
}
}
protected override void CreateChildControls()
{
Label LeftHandLabel = new Label();
LeftHandLabel.Text = LeftHandText;
this.Controls.Add(LeftHandLabel);
this.Controls.Add(new LiteralControl("     "));
for (int i = 1; i <= NumberOfRadio; i++)
{
RadioButton myRadio = new RadioButton();
myRadio.AutoPostBack = true;
myRadio.ID = (Convert.ToString(i));
myRadio.GroupName = "klaus";
myRadio.CheckedChanged += new
EventHandler(this.RadioButton_CheckedChanged);
this.Controls.Add(myRadio);
}
this.Controls.Add(new LiteralControl("</h3>"));
}
private void RadioButton_CheckedChanged(Object sender,
EventArgs e)
{
if (((RadioButton)sender).Checked)
{
this.SelectedValue = ((RadioButton)sender).ID;
this.Controls.Add(new
LiteralControl(this.selectedvalue));
}
}
}
}
--------------------------------
and the code an my aspx:
----------------------------------
protected void Button1_Click2(object sender, EventArgs e)
{
Response.Write("Eins:" + Composition3_1.SelectedValue+ "<br>");
Response.Write("Zwei " + Composition3_2.SelectedValue);
}
-------------------------------
The problem again: I do not get an value when I call
Composition3_1.SelectedValue. But I should get one, because my class
sets the value, when I click on a radiobutton.
Perhaps you have an idea.
Perhaps I lose the changes in my object (myobject.selectedvalue) when I
click the button on my aspx (postback problem?).
Thanks a lot.
Gellert