Home All Groups Group Topic Archive Search About

Repeat web controls in ASPX page

Author
16 Apr 2005 9:13 PM
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

Author
17 Apr 2005 6:59 AM
Riki
oSup wrote:
Show quoteHide quote
> 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.

--

Riki
Author
17 Apr 2005 10:53 PM
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)...

Show quoteHide quote
"Riki" <riki@nospam.com> wrote in message news:<uxK3AsxQFHA.2348@tk2msftngp13.phx.gbl>...
> oSup wrote:
> > 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.
Author
18 Apr 2005 1:44 PM
Riki
oSup wrote:
> 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 %>")

--

Riki
Author
18 Apr 2005 1:39 PM
Brock Allen
I just posted on another thread that does something similar (HTH):

http://groups-beta.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/5e4ba4cfe5902a4b/a5717a97bd32c450?q=Brock+Viewstate+and+dynamic+controls&rnum=1#a5717a97bd32c450

-Brock
DevelopMentor
http://staff.develop.com/ballen



Show quoteHide quote
> 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
>