K
Kirill Osipov
Hello everybody!
Sorry if it's not the right newsgroup to post my message to. Anyways, any
advice is very helpful to me as I am an absolute novice in Web Forms.
Here is a small piece of code. It is actually a lightweight scenario of what
is going to happen in my project.
------------------------------------------------
namespace bluebook
{
public class Testpage : Page
{
protected PlaceHolder ctlPlaceHolder; //ctlPlaceHolder also resides on the
corresponding aspx page
private void Page_Load(object sender, System.EventArgs e)
{
LinkButton aLB = new LinkButton();
aLB.CommandName = "Command 1";
aLB.Text = "Level 1";
aLB.Command += new CommandEventHandler(OnCommand);
ctlPlaceHolder.Controls.Add(aLB);
this.SaveViewState();
}
private void OnCommand(object sender, CommandEventArgs args)
{
LinkButton aLB = (LinkButton) sender;
int a = Int32.Parse( aLB.CommandName[8].ToString() );
a++;
LinkButton aNewLB = new LinkButton();
aNewLB.CommandName = "Command " + a.ToString();
aNewLB.Text = "Level " + a.ToString();
ctlPlaceHolder.Controls.Clear();
ctlPlaceHolder.Controls.Add(aNewLB);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
------------------------------------------------
What I was expecting is that every time I click the hyperlink, the form is
regenerated and the text inside the hyperlink is incremented. So first it
displays Level 1, then Level 2, then Level 3, ..., Level 10, Level 2, ...
and so on. But instead it only increments once, and then goes back to the
initial state.
I realize that changing the hyperlink's text can be achieved without
creating a new control each time an event is raised. But as I have already
said, this is just a sample, and in the real project I am working on I DO
NEED to create the control dynamically each time I process the event.
Does anyone know a workaround? Or, maybe, it is a bug in the technology?
Regards,
Kirill Osipov
Sorry if it's not the right newsgroup to post my message to. Anyways, any
advice is very helpful to me as I am an absolute novice in Web Forms.
Here is a small piece of code. It is actually a lightweight scenario of what
is going to happen in my project.
------------------------------------------------
namespace bluebook
{
public class Testpage : Page
{
protected PlaceHolder ctlPlaceHolder; //ctlPlaceHolder also resides on the
corresponding aspx page
private void Page_Load(object sender, System.EventArgs e)
{
LinkButton aLB = new LinkButton();
aLB.CommandName = "Command 1";
aLB.Text = "Level 1";
aLB.Command += new CommandEventHandler(OnCommand);
ctlPlaceHolder.Controls.Add(aLB);
this.SaveViewState();
}
private void OnCommand(object sender, CommandEventArgs args)
{
LinkButton aLB = (LinkButton) sender;
int a = Int32.Parse( aLB.CommandName[8].ToString() );
a++;
LinkButton aNewLB = new LinkButton();
aNewLB.CommandName = "Command " + a.ToString();
aNewLB.Text = "Level " + a.ToString();
ctlPlaceHolder.Controls.Clear();
ctlPlaceHolder.Controls.Add(aNewLB);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
------------------------------------------------
What I was expecting is that every time I click the hyperlink, the form is
regenerated and the text inside the hyperlink is incremented. So first it
displays Level 1, then Level 2, then Level 3, ..., Level 10, Level 2, ...
and so on. But instead it only increments once, and then goes back to the
initial state.
I realize that changing the hyperlink's text can be achieved without
creating a new control each time an event is raised. But as I have already
said, this is just a sample, and in the real project I am working on I DO
NEED to create the control dynamically each time I process the event.
Does anyone know a workaround? Or, maybe, it is a bug in the technology?
Regards,
Kirill Osipov