Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7636201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:36:53+00:00 2026-05-31T07:36:53+00:00

I have a repeater and each item contains a button which should redirect to

  • 0

I have a repeater and each item contains a button which should redirect to another page and also pass a value in the query string.

I am not getting any errors, but when I click the button, the page just refreshes (so I am assuming a postback does occur) and does not redirect. I think that for some reason, it isn’t recognizing the CommandName of the button.

Repeater code:


<asp:Repeater ID="MySponsoredChildrenList" runat="server" OnItemDataBound="MySponsoredChildrenList_ItemDataBound" OnItemCommand="MySponsoredChildrenList_ItemCommand">
    <HeaderTemplate>
    </HeaderTemplate>
    <ItemTemplate>
        <br />
        <div id="OuterDiv">
            <div id="InnerLeft">
                <asp:Image ID="ProfilePic" runat="server" ImageUrl='<%#"~/Resources/Children Images/" + String.Format("{0}", Eval("Primary_Image")) %>'
                    Width='300px' Style="max-height: 500px" /></div>
            <div id="InnerRight">
            <asp:HiddenField ID="ChildID" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "Child_ID") %>'/>   
                    <span style="font-size: 20px; font-weight:bold;"><%# DataBinder.Eval(Container.DataItem, "Name") %>
                    <%# DataBinder.Eval(Container.DataItem, "Surname") %></span>
                <br /><br /><br />

                What have you been up to?
                <br /><br />
                    <span style="font-style:italic">"<%# DataBinder.Eval(Container.DataItem, "MostRecentUpdate")%>"</span>    

                    <span style="font-weight:bold"> -<%# DataBinder.Eval(Container.DataItem, "Update_Date", "{0:dd/MM/yyyy}")%></span><br /><br /><br />Sponsored till:

                <%# DataBinder.Eval(Container.DataItem, "End_Date", "{0:dd/MM/yyyy}")%>
                <br /><br />

                <asp:Button ID="ChildProfileButton" runat="server" Text="View Profile"  CommandName="ViewProfile"  />
            </div>
        </div>
        <br />
    </ItemTemplate>
    <SeparatorTemplate>
        <div id="SeparatorDiv">
        </div>
    </SeparatorTemplate>
</asp:Repeater>

C# Code behind:


protected void MySponsoredChildrenList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                // Stuff to databind
                Button myButton = (Button)e.Item.FindControl("ChildProfileButton");

                myButton.CommandName = "ViewProfile";                }
        }

        protected void MySponsoredChildrenList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "ViewProfile")
            {
                int ChildIDQuery = Convert.ToInt32(e.Item.FindControl("ChildID"));
                Response.Redirect("~/ChildDescription.aspx?ID=" + ChildIDQuery);
            }

        }

I am new to using repeaters so it’s probably just a rookie mistake. On a side note: is there a better way of obtaining the ChildID without using a hidden field?

EDIT: Using breakpoints; the ItemDatabound event handler is being hit, but the ItemCommand is not being entered at all

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:36:55+00:00Added an answer on May 31, 2026 at 7:36 am

    You need to set MySponsoredChildrenList_ItemDataBound as protected. Right now, you have just ‘void’ which by default is private, and is not accessible to the front aspx page.

    Another way is to use the add event handler syntax from a function in your code behind, using the += operator.

    Either way, the breakpoint will now be hit and our code should mwork.

    EDIT: So the above solved the compilation error but the breakpoints are not being hit; I’ve ran some tests and am able to hit breakpoints like this:

    Since I do not know how you are databinding, I just added this code to my code-behind:

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                MySponsoredChildrenList.DataSource = new List<object>() { null };
                MySponsoredChildrenList.DataBind();
            }
        }
    

    Note: If you DataBind() and ItemDataBound() is called on every postback, it will wipe out the command argument, which is potentially what you are seeeing; so if you always see [object]_ItemDataBound() breakpoint hit, but never [object]_ItemCommand(), it is because you need to databind only on the initial page load, or after any major changes are made.

    Note also the method MySponsoredChildrenList_ItemCommand doesn’t work:

        protected void MySponsoredChildrenList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "ViewProfile")
            {
                int ChildIDQuery = Convert.ToInt32(e.Item.FindControl("ChildID"));
                Response.Redirect("~/ChildDescription.aspx?ID=" + ChildIDQuery);
            }
    
        }
    

    When you do FindControl, you need to cast to the correct control type, and also make sure to check for empty and null values before converting, or else you will possibly have errors:

        protected void MySponsoredChildrenList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "ViewProfile")
            {
                int childId = 0;
                var hiddenField = e.Item.FindControl("ChildID") as HiddenField;
                if (null != hiddenField)
                {
                    if (!string.IsNullOrEmpty(hiddenField.Value))
                    {
                        childId = Convert.ToInt32(hiddenField.Value);
                    }
                }
    
                if (childId > 0)
                {
                    Response.Redirect("~/ChildDescription.aspx?ID=" + childId);
                }
            }
    
        }
    

    Hope this helps – if not, please post additional code for the “full picture” of what is happening, so we can see where else you might have a problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery tab on my page, where each list item contains a
I have asp.net repeater on a page. If each item being repeated is wrapped
I have a repeater and an unbound checkbox in each item. I want to
I have some javascript in a repeater item which calls AC_FL_RunContent to load and
I have a repeater that outputs divs like the following for every item returned
I have a Repeater with a Button inside the ItemTemplate . I added the
I have a Repeater contol bound to a custom object (an EntitySpaces query) and
I have a repeater control outputting some HTML. I want a table which outputs
I have a repeater control that contains an ItemTemplate containing a databound label and
I have a Repeater in my page and after databinding, I have to click

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.