The basics of repeater

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maffarazo
    New Member
    • Apr 2009
    • 7

    The basics of repeater

    I'm going to make a website where you can purchase stuff..
    I'm having problems with the repeater. The problem is I dont know what to select in my repeater.

    it's something like this
    Code:
    <table cellpadding="0" cellspacing="0">
    <tr valign="top" >
        <td>Just nu har vi specialerbjudande på:
        </td>
    </tr>
    <tr>
    
        <asp:Repeater ID="repeater" runat="server">
               
               <ItemTemplate>
                      </tr>
                      <tr>
                            <td>
                           <%#DataBinder.Eval(Container.DataItem,"gdname")%>                           
                            </td>
                    
                         <td>
                                <asp:textbox id="Numbers" runat="server" />purchases
                         </td>
                   </tr>
                   <tr>
                         <td>
                               <asp:button id="btn1" runat="server" text="Purchase" onclick="purchase" />      
           </ItemTemplate>          
        </asp:Repeater>
                
       </tr> 
    </table>
    how do I get the information of wich goods they purshase? normally I would send a id with a label or something but all the labels on the site will have the same ID so the server wont know wich one to take the information from.

    same goes for the button

    so I just need the basics of how to use repeater, btw.. It seems I can't use labels inside the reapeter at all. can't find the id when writing, like it doesent exist at all

    Thx =)
    Last edited by Frinavale; Apr 16 '09, 07:29 PM. Reason: Added code tags. Please post code in [code] [/code] tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Well actually the ID of the Lables and Buttons within a Repeater all have unique IDs when they are rendered in the browser.

    The Repeater's NamingContainer takes care of that.

    To retrieve a Label or Button or Textbox (any control) from a repeater (or any other control that implements the INamingContinae r interface) you would use the FindControl() method.

    All the information you need on Repeaters and any other .NET controls can be found in the MSDN Library. This resource should get you pointed in the right direction....th ere are multiple articles on theRepeaters there. I recommend bookmarking the MSDN Library and using it as your primary resource when developing in .NET.

    Comment

    • maffarazo
      New Member
      • Apr 2009
      • 7

      #3
      Thank you very much =)

      Thx alot :D
      now can I finally finnish my project :P

      Comment

      • maffarazo
        New Member
        • Apr 2009
        • 7

        #4
        Only one problem =( dont know how to prevent this error to occur

        CS0122: 'test.Button1_C lick(object, System.EventArg s)' is inaccessible due to its protection level

        I used:
        Code:
         private void Button1_Click(object sender, EventArgs MyEventArgs)
            {
               
                Control myControl1 = FindControl("numbers");
                if (myControl1 != null)
                {
                    
                    Control myControl2 = myControl1.Parent;
                    Response.Write("Parent of the text box is : " + myControl2.ID);
                }
                else
                {
                    Response.Write("Control not found");
                }
            }
        any ideas? guess there's some settings I have to do?
        Last edited by PRR; Apr 17 '09, 12:01 PM. Reason: Please post code in [code] [/code] tags.

        Comment

        • maffarazo
          New Member
          • Apr 2009
          • 7

          #5
          to prevent this problem I changed it from private to public..

          but I still got the problem I had earlier when pressing a button

          Invalid postback or callback argument. Event validation is enabled using <pages enableEventVali dation="true"/> in configuration or <%@ Page EnableEventVali dation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptMan ager.RegisterFo rEventValidatio n method in order to register the postback or callback data for validation.

          that's the error I get, can anyone please help me?

          Comment

          • maffarazo
            New Member
            • Apr 2009
            • 7

            #6
            sorry for making so many posts in this one and not doing the "[code]" around the code.

            anyway, the only solution I have found so far is to use

            Code:
            <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" EnableEventValidation="false" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" Title="Untitled Page" %>
            in the site. but by doing so I lower the security on the site. Not that it matters.

            I also know that I can use ClientScriptMan ager.RegisterFo rEventValidatio n
            but I dont know how this works and I can't seem to find any information about it.
            anyone know?

            just one more thing. I'm using
            Code:
             private void Button1_Click(object sender, EventArgs MyEventArgs)
                 {
             
                   Control myControl1 = FindControl("numbers");
                     if (myControl1 != null)
                     {
              
                         Control myControl2 = myControl1.Parent;
                        Response.Write("Parent of the text box is : " + myControl2.ID);
                    }
                     else
                    {
                         Response.Write("Control not found");
                    }
                 }
            but i always get the control not found. arent I supposed to write the ID in findcontrol?
            Last edited by maffarazo; Apr 17 '09, 01:19 PM. Reason: # occured where there shouldnt be any

            Comment

            Working...