Dynamic ID in Webcontrol

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
 
R

Riki

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top