Asp repeater & LinkButton

  • Thread starter Thread starter Peter Kirk
  • Start date Start date
P

Peter Kirk

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 ...");
}
 
Hi,

No really, it should work fine.

What does Item_DataBound? the problem may lay there.

cheers,
 
Ignacio Machin ( .NET/ C# MVP ) said:
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
 
Back
Top