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="ResultsRepe ater" onitemdatabound ="Item_DataBoun d"
Runat="server">
<HeaderTemplate >
<table>
<tr>
<th>Name</th>
<th>Code</th>
</tr>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td><%# ((DataRow)Conta iner.DataItem). Name %></td>
<td>
<asp:LinkButt on id="MyButton"
OnClick="MyButt onMenuItem_Clic k" Runat="server" text="<%#
((DataRow)Conta iner.DataItem). Code %>" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate >
</table>
</FooterTemplate>
</asp:repeater>
In code behind:
private void Page_Load(objec t sender, System.EventArg s e)
{
log.Info("Page_ Load");
string detail = Request.Params["detail"];
if (!IsPostBack)
{
log.Info("Page_ Load !IsPostBack");
// Populates fields for supplying search criteria:
PopulateSearchD ropDowns();
}
else
{
log.Info("Page_ Load IsPostBack");
}
log.Info("PortT oPort Page_Load END");
}
// Never gets called
public void MyButtonMenuIte m_Click(object sender, EventArgs e)
{
log.Info("MyBut tonMenuItem_Cli ck");
LinkButton btn = (LinkButton)sen der;
// 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.EventArg s e)
{
log.Info("SendB utton_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_Clic k ...");
}
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="ResultsRepe ater" onitemdatabound ="Item_DataBoun d"
Runat="server">
<HeaderTemplate >
<table>
<tr>
<th>Name</th>
<th>Code</th>
</tr>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td><%# ((DataRow)Conta iner.DataItem). Name %></td>
<td>
<asp:LinkButt on id="MyButton"
OnClick="MyButt onMenuItem_Clic k" Runat="server" text="<%#
((DataRow)Conta iner.DataItem). Code %>" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate >
</table>
</FooterTemplate>
</asp:repeater>
In code behind:
private void Page_Load(objec t sender, System.EventArg s e)
{
log.Info("Page_ Load");
string detail = Request.Params["detail"];
if (!IsPostBack)
{
log.Info("Page_ Load !IsPostBack");
// Populates fields for supplying search criteria:
PopulateSearchD ropDowns();
}
else
{
log.Info("Page_ Load IsPostBack");
}
log.Info("PortT oPort Page_Load END");
}
// Never gets called
public void MyButtonMenuIte m_Click(object sender, EventArgs e)
{
log.Info("MyBut tonMenuItem_Cli ck");
LinkButton btn = (LinkButton)sen der;
// 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.EventArg s e)
{
log.Info("SendB utton_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_Clic k ...");
}
Comment