473,383 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Link button in repeater header

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.
Nov 19 '05 #1
3 4087
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" <sh**********@community.nospam>
| 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: <eO**************@tk2msftngp13.phx.gbl>
| 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.
|
|
|

Nov 19 '05 #2
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]" <st*****@online.microsoft.com> wrote in message
news:Dw**************@TK2MSFTNGXA01.phx.gbl...
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" <sh**********@community.nospam>
| 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: <eO**************@tk2msftngp13.phx.gbl>
| 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.
|
|
|

Nov 19 '05 #3
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" <sh**********@community.nospam>
| References: <eO**************@tk2msftngp13.phx.gbl>
<Dw**************@TK2MSFTNGXA01.phx.gbl>
| 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: <e2**************@TK2MSFTNGP10.phx.gbl>
| 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]" <st*****@online.microsoft.com> wrote in message
| news:Dw**************@TK2MSFTNGXA01.phx.gbl...
| > 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" <sh**********@community.nospam>
| > | 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: <eO**************@tk2msftngp13.phx.gbl>
| > | 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.
| > |
| > |
| > |
| >
|
|
|

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stan | last post by:
I cannot make the link buttons fire ItemCommand from repeater control. Here is the code: <asp:repeater id=rptLetters runat="server"> <itemtemplate> <asp:linkbutton id="lnkLetter"...
0
by: Robert Walter | last post by:
I was looking for a method to repeat the headers on an ASP.NET Repeater control. I couldn't find quite what I wanted on the web so I implemented it myself. I thought it maybe useful for some of you...
0
by: Pat Sagaser via .NET 247 | last post by:
I'm using a repeater with a dynamic template. I don't know the fields to display (or how many) until runtime. I have everything working except for linking Button events to the repeaters ItemCommand...
1
by: Keith Harris | last post by:
Hi, I have a Repeater control which is bound to a dataset. In the footer of the repeater control, I have a Button whose visibility I want to vary according to the sum of a column being > 0. ...
1
by: Mauritsius | last post by:
I have a simple page where I would like to modify a repeater (bounded to a dataset) if a button (outside the repeater) is clicked or not. I tried to solve this with a button click event that...
1
by: Imran Aziz | last post by:
Hello All, I have an asp:linkbutton in a repeater control, what I want to do is when someone clicks the link button I should get a value for the link button, and accordingly do some action. How...
2
by: Andy | last post by:
Hi, This is one of those things I thought should e easy... I'm programatically trying to set the navigateURL property in a hyperlink in the headertemplate of a repeater, but always get the...
3
by: Emma Middlebrook | last post by:
Hi there, I've been trying to implement a repeater control in an ASP.NET 2 page but I can't seem to get the layout exactly how I want and I'm not sure if it's something that I am doing wrong or...
5
by: Peter Larsen [CPH] | last post by:
Hi, The following sample shows a LinkButton in the HeaderTemplate of a Repeater control. The problem is that i'm not able to access the linkbutton in code (in the cs file) as long as the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.