Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Link button in repeater header

Reply
Thread Tools

Link button in repeater header

 
 
Shimon Sim
Guest
Posts: n/a
 
      08-18-2005
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.


 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      08-18-2005
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!tk2msft ngp13.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.
|
|
|

 
Reply With Quote
 
 
 
 
Shimon Sim
Guest
Posts: n/a
 
      08-18-2005
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...
> 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!tk2msft ngp13.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.
> |
> |
> |
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      08-19-2005
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!TK2MSFT NGP10.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...
| > 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!tk2msft ngp13.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.
| > |
| > |
| > |
| >
|
|
|

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Header files with "header.h" or <header.h> ?? mlt C++ 2 01-31-2009 02:54 PM
Handling link button in repeater control Imran Aziz ASP .Net 1 09-02-2005 05:01 PM
RE: Link Link Link =?Utf-8?B?REw=?= Windows 64bit 0 05-17-2005 12:15 PM
Re: Link Link Link DANGER WILL ROBINSON!!! Kevin Spencer ASP .Net 0 05-17-2005 10:41 AM
Problems with Link Button and Button web controls Suzanne ASP .Net Web Controls 0 12-03-2003 02:17 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57