473,320 Members | 1,884 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,320 software developers and data experts.

Asp repeater & LinkButton

Hi

are there any "gotchas" with using an asp:repeater that means that the
"onclick" method of a LinkButton created in the repaeter does not fire?

I at least cannot get it to work. I have a webpage where the user can enter
some search criteria (via dropdowns and textboxes) and then perform a search
and have results presented. The results list includes linkbuttons which the
user can click on to obtain more detailed results.

Here is some example code if anyone would be kind enough to offer advice.

On html/asp:

<asp:repeater id="ResultsRepeater" onitemdatabound="Item_DataBound"
Runat="server">
<HeaderTemplate>
<table>
<tr>
<th>Name</th>
<th>Code</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# ((DataRow)Container.DataItem).Name %></td>
<td>
<asp:LinkButton id="MyButton"
OnClick="MyButtonMenuItem_Click" Runat="server" text="<%#
((DataRow)Container.DataItem).Code %>" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:repeater>
In code behind:

private void Page_Load(object sender, System.EventArgs e)
{
log.Info("Page_Load");

string detail = Request.Params["detail"];

if (!IsPostBack)
{
log.Info("Page_Load !IsPostBack");

// Populates fields for supplying search criteria:
PopulateSearchDropDowns();
}
else
{
log.Info("Page_Load IsPostBack");
}

log.Info("PortToPort Page_Load END");
}

// Never gets called
public void MyButtonMenuItem_Click(object sender, EventArgs e)
{
log.Info("MyButtonMenuItem_Click");
LinkButton btn = (LinkButton)sender;

// Supposed to do stuff to handle the linkbutton click...
}

// Click-handler for the "send" button, which generates the data for the
repeater.
private void SendQueryButton_Click(object sender, System.EventArgs e)
{
log.Info("SendButton_Click ...");

// ... data handing/validation... call the database "Search" method to
get the data:
ArrayList results = Search();
ResultsRepeater.DataSource = results;
ResultsRepeater.DataBind();

log.Info("END SendButton_Click ...");
}
Nov 17 '05 #1
2 3774
Hi,

No really, it should work fine.

What does Item_DataBound? the problem may lay there.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Peter Kirk" <pk@alpha-solutions.dk> wrote in message
news:Og*************@TK2MSFTNGP15.phx.gbl...
Hi

are there any "gotchas" with using an asp:repeater that means that the
"onclick" method of a LinkButton created in the repaeter does not fire?

I at least cannot get it to work. I have a webpage where the user can
enter some search criteria (via dropdowns and textboxes) and then perform
a search and have results presented. The results list includes linkbuttons
which the user can click on to obtain more detailed results.

Here is some example code if anyone would be kind enough to offer advice.

On html/asp:

<asp:repeater id="ResultsRepeater" onitemdatabound="Item_DataBound"
Runat="server">
<HeaderTemplate>
<table>
<tr>
<th>Name</th>
<th>Code</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# ((DataRow)Container.DataItem).Name %></td>
<td>
<asp:LinkButton id="MyButton"
OnClick="MyButtonMenuItem_Click" Runat="server" text="<%#
((DataRow)Container.DataItem).Code %>" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:repeater>
In code behind:

private void Page_Load(object sender, System.EventArgs e)
{
log.Info("Page_Load");

string detail = Request.Params["detail"];

if (!IsPostBack)
{
log.Info("Page_Load !IsPostBack");

// Populates fields for supplying search criteria:
PopulateSearchDropDowns();
}
else
{
log.Info("Page_Load IsPostBack");
}

log.Info("PortToPort Page_Load END");
}

// Never gets called
public void MyButtonMenuItem_Click(object sender, EventArgs e)
{
log.Info("MyButtonMenuItem_Click");
LinkButton btn = (LinkButton)sender;

// Supposed to do stuff to handle the linkbutton click...
}

// Click-handler for the "send" button, which generates the data for the
repeater.
private void SendQueryButton_Click(object sender, System.EventArgs e)
{
log.Info("SendButton_Click ...");

// ... data handing/validation... call the database "Search" method to
get the data:
ArrayList results = Search();
ResultsRepeater.DataSource = results;
ResultsRepeater.DataBind();

log.Info("END SendButton_Click ...");
}

Nov 17 '05 #2
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> skrev
i en meddelelse news:OQ**************@tk2msftngp13.phx.gbl...
Hi,

No really, it should work fine.

What does Item_DataBound? the problem may lay there.


Hi

thanks for the reply. After more experimentation it does seem that the code
works as I would have expected it to, if I run it as a "stand-alone"
webpage. Unfortunately the ascx I am making is running inside a "container"
(a CMS) which appears to swallow these click events. I will need to
investigate further.

Peter
Nov 17 '05 #3

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

Similar topics

3
by: Mark | last post by:
I am looking for an example of using checkboxes in a repeater control where the checkbox state is persisted from page to page. Thank you, Mark
0
by: Amir | last post by:
Hi every one This is the problem: I have a UserControl that contains a Repeater and a few LinkButton. The Repeater generate some linkButton. I use this control for implementing paging solution...
1
by: olduncleamos | last post by:
Hello all, I am experimenting with the repeater control and ran into something that I wasn't expecting. I would appreciate if the experts can confirm or correct my understanding. Here is a...
3
by: Shimon Sim | last post by:
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...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
3
by: renil | last post by:
I have a repeater control that displays info. from a datatable. Each row in the repeater has a checkbox. Also, I have a delete linkbutton outside the repeater control. What I'm trying to do when...
0
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
0
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.