More in this section

Forums / Developing with Sitefinity / Asp:repeater onclick event not working with Sifenity 4.1

Asp:repeater onclick event not working with Sifenity 4.1

5 posts, 0 answered
  1. Shekar
    Shekar avatar
    35 posts
    Registered:
    11 Mar 2011
    08 Aug 2011
    Link to this post
    Hi Team,
    I am currently working with sitefinity 4.1 and i have created a user control which displays list of item in a Repeater control and onclick of that item, it will add the text to a Textbox control out side the Repeater control. i have integrated this user control in to sifenity 4.1.
    Now i have created a new page using sitefinity 4.1 and add this user control in to that page, and browsed the page. The onclick event in the repeater control is not working.
    below the code for the repeater.
    <asp:Repeater ID="rptTags" runat="server" DataSourceID="sqldsTags"
                                OnItemDataBound="rptTags_ItemDataBound">
                                <ItemTemplate>                                
                                    <asp:Button BackColor="Transparent" ID="btnTag" onClick="btnTag_Click" runat="server" Text='<%# Eval("TagValue") %>' BorderStyle="None" CssClass="sidebar-item-tag"  />                            
                                </ItemTemplate>
                            </asp:Repeater>
     <telerik:RadTextBox ID="rtbTagInput" CssClass="mtbTag" runat="server" Width="100%" />

    code added in CS file
     protected void btnTag_Click(object sender, EventArgs e)
        {
            Button btnTag = (Button)sender;
            taglist = rtbTagInput.Text;

            if (btnTag.BackColor == System.Drawing.Color.Yellow)
            {
                //remove tag from list
                taglist = taglist.Replace(btnTag.Text, "").Trim();
            }
            else
            {
                //add tag to list
                if (taglist == "")
                    taglist = btnTag.Text;
                else
                {
                    taglist += " " + btnTag.Text;
                }
            }
            rtbTagInput.Text = taglist;
            rptTags.DataBind();
        }

    i think we need to add the parameter EnableEventValidation="true" at top of the page.
    can you please suggest how can i add this parameter while creating pages from sitefinity 4.1

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    08 Aug 2011
    Link to this post
    Hello Shekar,

    Could you check whether you enabled the view state of the page?

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Shekar
    Shekar avatar
    35 posts
    Registered:
    11 Mar 2011
    08 Aug 2011
    Link to this post
    Thanks for your quick response.

    NO, EnableViewState is not enabled on the user control page, i think by default it will be true.

    Thanks
  4. Shekar
    Shekar avatar
    35 posts
    Registered:
    11 Mar 2011
    08 Aug 2011
    Link to this post
    Hi Team,

    i have created a Test.aspx page and included the same user control with contains repeater control and button with in it, and onclick of the button event the functionality is working fine on this page, but when i use the same user control with page created using the sitefinity4.1, the page getting reloaded every time when i click on the button with in the repeater control and the click event method is not called.

    can u please help me like what settings to be made over here for making the page not reloaded on button click with in the repeater control
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    08 Aug 2011
    Link to this post
    Hello Shekar,

    Try this code

    template

    <asp:Repeater ID="rptTags" runat="server" >
        <ItemTemplate>                               
               <asp:Button BackColor="Transparent" ID="btnTag"  runat="server" Text="SomeText" BorderStyle="None" CssClass="sidebar-item-tag"  />                           
    </ItemTemplate>
    </asp:Repeater>


    code behind

    namespace SitefinityWebApp.Controls
    {
        public partial class Test : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
     
     
                rptTags.DataSource = TestSource();
                rptTags.ItemDataBound += new RepeaterItemEventHandler(rptTags_ItemDataBound);
                rptTags.DataBind();
            }
     
            void rptTags_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
                {
                    var btn = e.Item.FindControl("btnTag") as Button;
                    if (btn != null)
                    {
                        btn.Click += new EventHandler(btn_Click);
                    }
                }
            }
     
            void btn_Click(object sender, EventArgs e)
            {
                
            }
     
     
            public List<string> TestSource()
            {
     
                var list = new List<string>();
                for (int i = 0; i < 10; i++)
                {
                    list.Add("string item" + i);
                }
     
                return list;
            }
        }
     
     
        
    }


    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
5 posts, 0 answered