Link button in repeater header

Discussion in 'ASP .Net' started by Shimon Sim, Aug 18, 2005.

  1. Shimon Sim

    Shimon Sim Guest

    I put linkbutton in a repeater header. I attached event handler in makeup as
    onclick="btnSort_Click".
    Made btnSort_Click method public. It doesn't fire if I click on it. I tried
    to attach it in ItemDataBound event but I think it is too late.

    What am I doing wrong?
    Thanks
    Shimon.
    Shimon Sim, Aug 18, 2005
    #1
    1. Advertising

  2. Hi Shimon,

    Welcome to ASPNET newsgroup.
    As for the event handler of the repeater nested linkbutton not work
    problem, I'm thinking whether its a page specific problem. Generally, for
    such sub control, we can register event handler for them through :

    1. inline attribute in aspx page as you mentioned

    2. programmatically register event handler in the repeater's ItemCreated
    event.

    To make it clear, I've made a simple test page which demonstrate both the
    two means, you can have a test on your side to see whether there're any
    difference between your problem page. Here is the code, hope helps:

    =======aspx========
    <HTML>
    <HEAD>
    <title>simplerepeater</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema"
    content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body>
    <form id="Form1" method="post" runat="server">
    <asp:Repeater id="rptMain" runat="server">
    <HeaderTemplate>
    <br>
    <hr>
    <br>
    <asp:LinkButton ID="btnStatic" Runat="server"
    OnClick="btnStatic_Click">Static Handler</asp:LinkButton>
    <asp:LinkButton ID="btnDynamic" Runat="server">Dynamic
    Handler</asp:LinkButton>
    <br>
    <hr>
    </HeaderTemplate>
    <ItemTemplate>
    <br>
    <%# Container.DataItem %>
    </ItemTemplate>
    </asp:Repeater>
    </form>
    </body>
    </HTML>

    ========code behind=======
    public class simplerepeater : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Repeater rptMain;

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!IsPostBack)
    {
    string[] items = {"aaa","bbb","ccc","ddd","eee","fff"};
    rptMain.DataSource = items;
    rptMain.DataBind();
    }
    }


    protected void btnStatic_Click(object sender, EventArgs e)
    {
    Response.Write("<br>Static Link Button is clicked!");
    }

    protected void btnDynamic_Click(object sender, EventArgs e)
    {
    Response.Write("<br>Dynamic Link Button is clicked!");
    }


    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.rptMain.ItemCreated += new
    System.Web.UI.WebControls.RepeaterItemEventHandler(this.rptMain_ItemCreated)
    ;
    this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

    private void rptMain_ItemCreated(object sender,
    System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.Header)
    {
    LinkButton btn = e.Item.FindControl("btnDynamic") as LinkButton;
    if(btn != null)
    {
    btn.Click +=new EventHandler(btnDynamic_Click);
    }
    }
    }
    }



    --------------------
    | From: "Shimon Sim" <>
    | Subject: Link button in repeater header
    | Date: Wed, 17 Aug 2005 23:20:21 -0400
    | Lines: 10
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
    | X-RFC2646: Format=Flowed; Original
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
    | Message-ID: <>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet:118785
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | I put linkbutton in a repeater header. I attached event handler in makeup
    as
    | onclick="btnSort_Click".
    | Made btnSort_Click method public. It doesn't fire if I click on it. I
    tried
    | to attach it in ItemDataBound event but I think it is too late.
    |
    | What am I doing wrong?
    | Thanks
    | Shimon.
    |
    |
    |
    Steven Cheng[MSFT], Aug 18, 2005
    #2
    1. Advertising

  3. Shimon Sim

    Shimon Sim Guest

    Yes, you I right.
    The problem was that I disabled view state for the repeater so the control
    was never created after post back.
    Thank you,
    Shimon.

    "Steven Cheng[MSFT]" <> wrote in message
    news:D...
    > Hi Shimon,
    >
    > Welcome to ASPNET newsgroup.
    > As for the event handler of the repeater nested linkbutton not work
    > problem, I'm thinking whether its a page specific problem. Generally, for
    > such sub control, we can register event handler for them through :
    >
    > 1. inline attribute in aspx page as you mentioned
    >
    > 2. programmatically register event handler in the repeater's ItemCreated
    > event.
    >
    > To make it clear, I've made a simple test page which demonstrate both the
    > two means, you can have a test on your side to see whether there're any
    > difference between your problem page. Here is the code, hope helps:
    >
    > =======aspx========
    > <HTML>
    > <HEAD>
    > <title>simplerepeater</title>
    > <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    > <meta name="CODE_LANGUAGE" Content="C#">
    > <meta name="vs_defaultClientScript" content="JavaScript">
    > <meta name="vs_targetSchema"
    > content="http://schemas.microsoft.com/intellisense/ie5">
    > </HEAD>
    > <body>
    > <form id="Form1" method="post" runat="server">
    > <asp:Repeater id="rptMain" runat="server">
    > <HeaderTemplate>
    > <br>
    > <hr>
    > <br>
    > <asp:LinkButton ID="btnStatic" Runat="server"
    > OnClick="btnStatic_Click">Static Handler</asp:LinkButton>
    > <asp:LinkButton ID="btnDynamic" Runat="server">Dynamic
    > Handler</asp:LinkButton>
    > <br>
    > <hr>
    > </HeaderTemplate>
    > <ItemTemplate>
    > <br>
    > <%# Container.DataItem %>
    > </ItemTemplate>
    > </asp:Repeater>
    > </form>
    > </body>
    > </HTML>
    >
    > ========code behind=======
    > public class simplerepeater : System.Web.UI.Page
    > {
    > protected System.Web.UI.WebControls.Repeater rptMain;
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > if(!IsPostBack)
    > {
    > string[] items = {"aaa","bbb","ccc","ddd","eee","fff"};
    > rptMain.DataSource = items;
    > rptMain.DataBind();
    > }
    > }
    >
    >
    > protected void btnStatic_Click(object sender, EventArgs e)
    > {
    > Response.Write("<br>Static Link Button is clicked!");
    > }
    >
    > protected void btnDynamic_Click(object sender, EventArgs e)
    > {
    > Response.Write("<br>Dynamic Link Button is clicked!");
    > }
    >
    >
    > #region Web Form Designer generated code
    > override protected void OnInit(EventArgs e)
    > {
    > //
    > // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    > //
    > InitializeComponent();
    > base.OnInit(e);
    > }
    >
    > /// <summary>
    > /// Required method for Designer support - do not modify
    > /// the contents of this method with the code editor.
    > /// </summary>
    > private void InitializeComponent()
    > {
    > this.rptMain.ItemCreated += new
    > System.Web.UI.WebControls.RepeaterItemEventHandler(this.rptMain_ItemCreated)
    > ;
    > this.Load += new System.EventHandler(this.Page_Load);
    >
    > }
    > #endregion
    >
    > private void rptMain_ItemCreated(object sender,
    > System.Web.UI.WebControls.RepeaterItemEventArgs e)
    > {
    > if(e.Item.ItemType == ListItemType.Header)
    > {
    > LinkButton btn = e.Item.FindControl("btnDynamic") as LinkButton;
    > if(btn != null)
    > {
    > btn.Click +=new EventHandler(btnDynamic_Click);
    > }
    > }
    > }
    > }
    >
    >
    >
    > --------------------
    > | From: "Shimon Sim" <>
    > | Subject: Link button in repeater header
    > | Date: Wed, 17 Aug 2005 23:20:21 -0400
    > | Lines: 10
    > | X-Priority: 3
    > | X-MSMail-Priority: Normal
    > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
    > | X-RFC2646: Format=Flowed; Original
    > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
    > | Message-ID: <>
    > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    > | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
    > | Xref: TK2MSFTNGXA01.phx.gbl
    > microsoft.public.dotnet.framework.aspnet:118785
    > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > |
    > | I put linkbutton in a repeater header. I attached event handler in
    > makeup
    > as
    > | onclick="btnSort_Click".
    > | Made btnSort_Click method public. It doesn't fire if I click on it. I
    > tried
    > | to attach it in ItemDataBound event but I think it is too late.
    > |
    > | What am I doing wrong?
    > | Thanks
    > | Shimon.
    > |
    > |
    > |
    >
    Shimon Sim, Aug 18, 2005
    #3
  4. You're welcome Shimon,

    Have a nice day!

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    --------------------
    | From: "Shimon Sim" <>
    | References: <>
    <>
    | Subject: Re: Link button in repeater header
    | Date: Thu, 18 Aug 2005 08:19:12 -0400
    | Lines: 159
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
    | X-RFC2646: Format=Flowed; Original
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
    | Message-ID: <e2XMB7#>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet:118839
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | Yes, you I right.
    | The problem was that I disabled view state for the repeater so the control
    | was never created after post back.
    | Thank you,
    | Shimon.
    |
    | "Steven Cheng[MSFT]" <> wrote in message
    | news:D...
    | > Hi Shimon,
    | >
    | > Welcome to ASPNET newsgroup.
    | > As for the event handler of the repeater nested linkbutton not work
    | > problem, I'm thinking whether its a page specific problem. Generally,
    for
    | > such sub control, we can register event handler for them through :
    | >
    | > 1. inline attribute in aspx page as you mentioned
    | >
    | > 2. programmatically register event handler in the repeater's ItemCreated
    | > event.
    | >
    | > To make it clear, I've made a simple test page which demonstrate both
    the
    | > two means, you can have a test on your side to see whether there're any
    | > difference between your problem page. Here is the code, hope helps:
    | >
    | > =======aspx========
    | > <HTML>
    | > <HEAD>
    | > <title>simplerepeater</title>
    | > <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    | > <meta name="CODE_LANGUAGE" Content="C#">
    | > <meta name="vs_defaultClientScript" content="JavaScript">
    | > <meta name="vs_targetSchema"
    | > content="http://schemas.microsoft.com/intellisense/ie5">
    | > </HEAD>
    | > <body>
    | > <form id="Form1" method="post" runat="server">
    | > <asp:Repeater id="rptMain" runat="server">
    | > <HeaderTemplate>
    | > <br>
    | > <hr>
    | > <br>
    | > <asp:LinkButton ID="btnStatic" Runat="server"
    | > OnClick="btnStatic_Click">Static Handler</asp:LinkButton>
    | > <asp:LinkButton ID="btnDynamic" Runat="server">Dynamic
    | > Handler</asp:LinkButton>
    | > <br>
    | > <hr>
    | > </HeaderTemplate>
    | > <ItemTemplate>
    | > <br>
    | > <%# Container.DataItem %>
    | > </ItemTemplate>
    | > </asp:Repeater>
    | > </form>
    | > </body>
    | > </HTML>
    | >
    | > ========code behind=======
    | > public class simplerepeater : System.Web.UI.Page
    | > {
    | > protected System.Web.UI.WebControls.Repeater rptMain;
    | >
    | > private void Page_Load(object sender, System.EventArgs e)
    | > {
    | > if(!IsPostBack)
    | > {
    | > string[] items = {"aaa","bbb","ccc","ddd","eee","fff"};
    | > rptMain.DataSource = items;
    | > rptMain.DataBind();
    | > }
    | > }
    | >
    | >
    | > protected void btnStatic_Click(object sender, EventArgs e)
    | > {
    | > Response.Write("<br>Static Link Button is clicked!");
    | > }
    | >
    | > protected void btnDynamic_Click(object sender, EventArgs e)
    | > {
    | > Response.Write("<br>Dynamic Link Button is clicked!");
    | > }
    | >
    | >
    | > #region Web Form Designer generated code
    | > override protected void OnInit(EventArgs e)
    | > {
    | > //
    | > // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    | > //
    | > InitializeComponent();
    | > base.OnInit(e);
    | > }
    | >
    | > /// <summary>
    | > /// Required method for Designer support - do not modify
    | > /// the contents of this method with the code editor.
    | > /// </summary>
    | > private void InitializeComponent()
    | > {
    | > this.rptMain.ItemCreated += new
    | >
    System.Web.UI.WebControls.RepeaterItemEventHandler(this.rptMain_ItemCreated)
    | > ;
    | > this.Load += new System.EventHandler(this.Page_Load);
    | >
    | > }
    | > #endregion
    | >
    | > private void rptMain_ItemCreated(object sender,
    | > System.Web.UI.WebControls.RepeaterItemEventArgs e)
    | > {
    | > if(e.Item.ItemType == ListItemType.Header)
    | > {
    | > LinkButton btn = e.Item.FindControl("btnDynamic") as LinkButton;
    | > if(btn != null)
    | > {
    | > btn.Click +=new EventHandler(btnDynamic_Click);
    | > }
    | > }
    | > }
    | > }
    | >
    | >
    | >
    | > --------------------
    | > | From: "Shimon Sim" <>
    | > | Subject: Link button in repeater header
    | > | Date: Wed, 17 Aug 2005 23:20:21 -0400
    | > | Lines: 10
    | > | X-Priority: 3
    | > | X-MSMail-Priority: Normal
    | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
    | > | X-RFC2646: Format=Flowed; Original
    | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
    | > | Message-ID: <>
    | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | > | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    | > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
    | > | Xref: TK2MSFTNGXA01.phx.gbl
    | > microsoft.public.dotnet.framework.aspnet:118785
    | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    | > |
    | > | I put linkbutton in a repeater header. I attached event handler in
    | > makeup
    | > as
    | > | onclick="btnSort_Click".
    | > | Made btnSort_Click method public. It doesn't fire if I click on it. I
    | > tried
    | > | to attach it in ItemDataBound event but I think it is too late.
    | > |
    | > | What am I doing wrong?
    | > | Thanks
    | > | Shimon.
    | > |
    | > |
    | > |
    | >
    |
    |
    |
    Steven Cheng[MSFT], Aug 19, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    840
  2. Kevin Spencer

    Re: Link Link Link DANGER WILL ROBINSON!!!

    Kevin Spencer, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    791
    Kevin Spencer
    May 17, 2005
  3. Imran Aziz

    Handling link button in repeater control

    Imran Aziz, Sep 2, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,829
    Imran Aziz
    Sep 2, 2005
  4. mlt
    Replies:
    2
    Views:
    807
    Jean-Marc Bourguet
    Jan 31, 2009
  5. Suzanne

    Problems with Link Button and Button web controls

    Suzanne, Dec 3, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    148
    Suzanne
    Dec 3, 2003
Loading...

Share This Page