Repeat web controls in ASPX page

Discussion in 'ASP .Net Web Controls' started by oSup, Apr 16, 2005.

  1. oSup

    oSup Guest

    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
     
    oSup, Apr 16, 2005
    #1
    1. Advertising

  2. oSup

    Riki Guest

    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.

    --

    Riki
     
    Riki, Apr 17, 2005
    #2
    1. Advertising

  3. oSup

    oSup Guest

    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)...

    "Riki" <> wrote in message news:<>...
    > 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.
     
    oSup, Apr 17, 2005
    #3
  4. oSup

    Brock Allen Guest

    I just posted on another thread that does something similar (HTH):

    http://groups-beta.google.com/group... and dynamic controls&rnum=1#a5717a97bd32c450

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



    > 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
    >
     
    Brock Allen, Apr 18, 2005
    #4
  5. oSup

    Riki Guest

    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
     
    Riki, Apr 18, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page