Asp:repeater onclick event not working with Sifenity 4.1

Posted by Community Admin on 04-Aug-2018 08:03

Asp:repeater onclick event not working with Sifenity 4.1

All Replies

Posted by Community Admin on 08-Aug-2011 00:00

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

Posted by Community Admin on 08-Aug-2011 00:00

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

Posted by Community Admin on 08-Aug-2011 00:00

Thanks for your quick response.

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

Thanks

Posted by Community Admin on 08-Aug-2011 00:00

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

Posted by Community Admin on 08-Aug-2011 00:00

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

This thread is closed