Dynamic ID in Webcontrol

  • Thread starter Thread starter Andre
  • Start date Start date
A

Andre

Hi.
There is a way, that I can create a dynamic ID in a WebControl.
This doesn´t work, but, looks like what I want:

<asp:Button ID="btnAdd<%="1"%>" runat="server" Text="Add Resposta"
OnClick="btnAdd_Click" />

I´ve tried to set up the id at the finish of the aspx, but, when I get
in the codebehind, the id is the original.
Doesn´t change.

What I looking for is:
I have many usercontrols in a page, I need a way to get a value that
represents the unique usercontrol clicked.
For this, I need the dynamic id in the button to diferentiate a user
control from anothers.
Changing the id in postback like this:
if (!Page.IsPostBack)
{
btnAdd.ID = "btnAdd" + _hdPerguntaID;
}

doesn´t work because I´m using ajax extensions and the page always is
in PostBack.

Thanks in advance

Andre
 
Andre said:
Hi.
There is a way, that I can create a dynamic ID in a WebControl.
This doesn´t work, but, looks like what I want:

<asp:Button ID="btnAdd<%="1"%>" runat="server" Text="Add Resposta"
OnClick="btnAdd_Click" />

I´ve tried to set up the id at the finish of the aspx, but, when I get
in the codebehind, the id is the original.
Doesn´t change.

What I looking for is:
I have many usercontrols in a page, I need a way to get a value that
represents the unique usercontrol clicked.
For this, I need the dynamic id in the button to diferentiate a user
control from anothers.
Changing the id in postback like this:
if (!Page.IsPostBack)
{
btnAdd.ID = "btnAdd" + _hdPerguntaID;
}

doesn´t work because I´m using ajax extensions and the page always is
in PostBack.

Thanks in advance

Andre

Changing the ID dynamically seems inappropriate to me, because the ID
is essential for the postback mechanism.

But the actual ID of the different buttons in the page will be composed
of the user control ID and the button ID, something like
MyUserControl1_btnAdd.
I suggest extracting the number from that ID, which will give you a unique
number for each user control.
 
Back
Top