Repeat web controls in ASPX page

O

oSup

Hi,

I would like to create list of handled buttons with variable label
within a code. Something like that:

....
<body>
<%
foreach (Information information in Informations) {
%>
<!-- here will be a logic depending on the information - for example
some conditions and different peices of code... that's a reason, why I
cannot use repeater -->

<asp:button runat="server" name="button1"
Text="<%=information.Name%>"/>
<%
}
%>
</body>
....

It of course doesn't work. But how to make this simple example
working?

Thank you!

osup
 
R

Riki

oSup said:
Hi,

I would like to create list of handled buttons with variable label
within a code. Something like that:

...
<body>
<%
foreach (Information information in Informations) {
%>
<!-- here will be a logic depending on the information - for example
some conditions and different peices of code... that's a reason, why I
cannot use repeater -->

<asp:button runat="server" name="button1"
Text="<%=information.Name%>"/>
<%
}
%>
</body>
...

It of course doesn't work. But how to make this simple example
working?

The solution here is probably to produce the HTML for the buttons
yourself, instead of using Button web controls.
Instead of
<asp:button ...>
write:
<input type="submit" value="<%=information.Name%>">

This is easy to understand if you know that the
<%= %> syntax is executed when the page is rendered,
and at that time, you are not allowed to add web controls anymore.
 
O

oSup

Thanks for your answer. But I have to use web controls (not exactly
asp:button, but some other third party components). And on the other
side - if I will use repeater (i don't like it, because I have no
control of presented information, and compose presented information in
code-behind page is in contrast with common use of the class as
"controller" - that's just my humble opinion), how can I operate with
generated buttons in client javascript functions? (because buttons
have some wierd id's)...
 
R

Riki

oSup said:
Thanks for your answer. But I have to use web controls (not exactly
asp:button, but some other third party components). And on the other
side - if I will use repeater (i don't like it, because I have no
control of presented information, and compose presented information in
code-behind page is in contrast with common use of the class as
"controller" - that's just my humble opinion), how can I operate with
generated buttons in client javascript functions? (because buttons
have some wierd id's)...

This last question I can answer.

Use Button1.ClientID like this:

document.getElementById("<%=Button1.ClientID %>")
 

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,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top