LinkButton in RadListView inside UserControl is not firing click event.

9 posts, 1 answers
  1. Damodar
    Damodar avatar
    55 posts
    Member since:
    Jan 2011

    Posted 06 Feb 2013 Link to this post

    Hi,

    I have page it contains 3 user controls.
    Each user control contains RadListView in which there are list of link buttons.

    Why is click event is not firing when user clicks link button?

    Best Regards,
    Damodar
  2. Damodar
    Damodar avatar
    55 posts
    Member since:
    Jan 2011

    Posted 06 Feb 2013 Link to this post


    Click event fires only if I load the RadListView in user controls Init method?

    Question:
    I registered all three user controls in the page.
    When ever click event is fired it will load all 3 user controls' Init method.
    Even though link button is clicked in user control 1.
     
    How to load only user control whose link button is clicked?
    (As RadListView is loading data from data base)
    OR Stop loading all user controls!

    Is there better way to load user controls in aspx page depending on your choice?

    Best Regards,
    Damodar
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Chris
    Chris avatar
    58 posts
    Member since:
    Feb 2012

    Posted 06 Feb 2013 Link to this post

    Any chance you could post your code here ?

    Cheers
  5. Damodar
    Damodar avatar
    55 posts
    Member since:
    Jan 2011

    Posted 06 Feb 2013 Link to this post

    <%@ Page Title="" Language="C#" MasterPageFile="~/Mobile.Master" AutoEventWireup="true" CodeBehind="Search.aspx.cs" Inherits="Mobile.Search" %><br> <br><%@ Register src="~/Mobile/Controls/Hardware.ascx" tagprefix="UCH" tagname="UC_Hardware" %><br>..<br><asp:Content ID="Content1" ContentPlaceHolderID="MobileContentPlaceHolder" runat="server">            <br>    <UCH:UC_Hardware ID="UCHardware" Visible="false" runat="server" /><br>  ..<br></asp:Content>

    codebehind
    public partial class Search : System.Web.UI.Page   
    {               
    protected void Page_Load(object sender, EventArgs e)       
    {            if (!IsPostBack)           
    LoadTargetUC(); 
            }
    private void LoadTargetUC()<span class="Apple-tab-span" style="white-space:pre"> </span>{       
    sstring target = string.Empty;      
     target = Request.QueryString["page"] as string;       
    if (!string.IsNullOrEmpty(target))        {           
    List<
    string> QueryList = new List<string> { "Hardware", "Software", "Misc" };           
    if (QueryList.Contains(target))            {               
    switch (target)
                    {                   
    case ("Hardware"):
                            
    UCHardware.Visible = true;                       
    UCHardware.Load_Contorls();                       
    break;.....

    In User Control
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Hardware.ascx.cs" Inherits="Control_Hardware" %>
    <
    telerik:RadListView ID="RadLVHardware" runat="server" AllowPaging="True">       
    <
    ItemTemplate>           
    <
    ul>
    <
    li>                                       
    <
    asp:LinkButton OnCommand="lnkHardwareList_Command" ID="lnkShipList" runat="server" Text='<%# Eval(" CommandArgument='<%#((System.Data.DataRowView)Container.DataItem)["HardwareID"]%>'                        CommandName="Hardware" CausesValidation="false" />               
    </
    li>           
    </
    ul>       
    </
    ItemTemplate>    </telerik:RadListView>


    Code Behind
    protected void lnkHardwareList_Command(object sender, CommandEventArgs e){
    string paramValue = Convert.ToString(e.CommandArgument)
    override protected void OnInit(EventArgs e){Load_Controls();}
    public void Load_Contorls()
    {CommonProcess common = new CommonProcess();
    DataSet ds = common.GetHardwareList() as DataSet;
    if (ds != null){               
    RadLVHardware.DataSource = ds;
    RadLVHardware.DataBind();}}

    protected void lnkHardwareList_Command(object sender, CommandEventArgs e)
    {
    string paramValue = Convert.ToString(e.CommandArgument)
    ...
    }
  6. Chris
    Chris avatar
    58 posts
    Member since:
    Feb 2012

    Posted 07 Feb 2013 Link to this post

    God !! Some formatting never hurt anyone plz :) Ctrl-K + Ctrl-D is your friend.

    I bet your code as shown here doesn't compile right ?
    So far I can only strongly advise you to revise the way you are loading your usercontrols. Check this demo using the RadAjaxManager here and its online documentation there

    You should be alright with that.
    Let me know how you go.

    Chris
  7. Damodar
    Damodar avatar
    55 posts
    Member since:
    Jan 2011

    Posted 12 Feb 2013 Link to this post

    Hi Chris,

    Thanks for the tips for formatting :). 

    I have master page while trying the tutorial, I got following error. 

    Multiple controls with the same ID 'ControlHardware' were found. FindControl requires that controls have unique IDs.


    When I checked public
     void LoadUserControl(string controlName) ran two times. If I put
    if (LatestLoadedControlName != null)
    {
    LoadUserControl(LatestLoadedControlName);
    }
        else
    LoadUserControl("~/Control/Hardware.ascx");
    Is there any way we can stop it? Best Regards, Damdoar
  8. Answer
    Chris
    Chris avatar
    58 posts
    Member since:
    Feb 2012

    Posted 13 Feb 2013 Link to this post

    May be you could try something like this (considering "PContent" is an asp:Panel):

    private string LatestLoadedControlName
    {
        get
        {
            return (string)ViewState["LatestLoadedControlName"];
        }
        set
        {
            ViewState["LatestLoadedControlName"] = value;
        }
    }
     
    protected void Page_Load(object sender, EventArgs e)
    {
        if (LatestLoadedControlName != null)
        {
            LoadUserControl(LatestLoadedControlName);
        }
        else
        {
            LoadUserControl("~/Control/Hardware.ascx");
        }
    }
     
    public void LoadUserControl(string controlName)
    {
        if (LatestLoadedControlName != null)
        {
            Control previousControl = PContent.FindControl(LatestLoadedControlName.Replace("~/Control/", "").Split('.')[0]);
            if (!Object.Equals(previousControl, null))
            {
                this.PContent.Controls.Remove(previousControl);
                previousControl.Dispose();
            }
        }
        string userControlID = controlName.Replace("~/Control/", "").Split('.')[0];
        Control targetControl = PContent.FindControl(userControlID);
        if (Object.Equals(targetControl, null))
        {
            UserControl userControl = (UserControl)this.LoadControl(controlName);
            userControl.ID = userControlID.Replace("/", "").Replace("~", "");
            this.PContent.Controls.Add(userControl);
            LatestLoadedControlName = controlName;
        }
    }


    Obviously your code can't work and loops indefinitely (shouldn't there be an exception). It runs only twice b/c it fails the second time.
    Let say that on the first call your LatestLoadedControlName is equal to null, therefore it loops back to the same method and tries to load your "~/Control/Hardware.ascx".
    This time your string controlName is equal to "~/Control/Hardware.ascx" but you never use it anyway ???? Hence you try to load your "~/Control/Hardware.ascx" again and again and again and ......

    If your LatestLoadedControlName != null then you end up in an infinite loop.


    Dude, my advise ? Read your code carefully.

  9. Damodar
    Damodar avatar
    55 posts
    Member since:
    Jan 2011

    Posted 24 Feb 2013 Link to this post

    Hi Chris,

    Thanks! 
    Thought telerik code works out of box.
    Didn't realize telerik example code need to be modified.


    Best Regards,
    Damodar
  10. Damodar
    Damodar avatar
    55 posts
    Member since:
    Jan 2011

    Posted 28 Feb 2013 Link to this post

    Hi Chris,

    Thanks for your help.

    Page load is hitting two times, When every list button is clicked.
    Can we stop this? I am not sure why is this happening.

    Best Regards,
    Damodar
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017