472,954 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Problem with OnItemCommand event and Loadtemplate

Hi all,
in my previous post I've wrong typed some tems.. this is the corrected post.

in a aspx page I have a repeater like this:
<asp:repeater id=repeaterResults runat="server"
OnItemCommand="RepeaterResult_Event">
<HeaderTemplate>
<table width="515" border="0" cellpadding="3" cellspacing="0">
</HeaderTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
<SeparatorTemplate>
<tr><td colspan="4"><hr></td></tr>
</SeparatorTemplate>
</asp:repeater>

in the code behind file I dinamically load the Itemtemplate with this code:

repeaterResults.DataSource = objPds;
string templateName = "templates/BSResultTextTemplate.ascx";
repeaterResults.ItemTemplate = Page.LoadTemplate(templateName);
repeaterResults.DataBind();

Always in the same code behind file, I've defined the Method specified in
the OnItemCommand property of repeater:

public void RepeaterResult_Event(object sender, RepeaterCommandEventArgs e)
{
string s = " SSS ";
}

below you can see the content of BSResultTextTemplate.ascx :
<tr>
<td class="nerotesti" width="155"><asp:LinkButton id="CmdVisualizzaReperto"
runat="server" CommandName="ItemCommand" CommandArgument=<%#
DataBinder.Eval(Container,"DataItem.ID") %> ><%#
DataBinder.Eval(Container,"DataItem.ID") %></asp:LinkButton></td>
<td class="nerotesti" width="160"><%#
DataBinder.Eval(Container,"DataItem.Culture") %></td>
<td class="nerotesti" width="160"><%#
DataBinder.Eval(Container,"DataItem.Subject") %></td>
<td class="nerotesti" width="60"> </td>
</tr>

Now the problem.... the template is loaded successfully but when I click on
one of the linkbutton generated, the method RepeaterResult_Event is not
fired...
on the other side if I insert the code of template directly in the repeater
definitition and don't load an external template when I click on one of the
linkbutton generated all work fine and the method RepeaterResult_Event is
invoked.

Please have anyone a solution for this?

Thank you.
Antonio.

Nov 19 '05 #1
4 1893
What i understood from your code is
your should not specify ItemCommand event in aspx file
it should be in your code-behind file.

Create a reference variable for your repeater (repeaterResults) in your cs
file, and go to InitializeComponent method and add ItemCommand event for
this control. It should work.

Do post if you've more problem.

Vadivel Kumar
http://blogs.wdevs.com/varahe

"Antonio Carpentieri" <An****************@discussions.microsoft.com> wrote
in message news:0A**********************************@microsof t.com...
Hi all,
in my previous post I've wrong typed some tems.. this is the corrected post.
in a aspx page I have a repeater like this:
<asp:repeater id=repeaterResults runat="server"
OnItemCommand="RepeaterResult_Event">
<HeaderTemplate>
<table width="515" border="0" cellpadding="3" cellspacing="0">
</HeaderTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
<SeparatorTemplate>
<tr><td colspan="4"><hr></td></tr>
</SeparatorTemplate>
</asp:repeater>

in the code behind file I dinamically load the Itemtemplate with this code:
repeaterResults.DataSource = objPds;
string templateName = "templates/BSResultTextTemplate.ascx";
repeaterResults.ItemTemplate = Page.LoadTemplate(templateName);
repeaterResults.DataBind();

Always in the same code behind file, I've defined the Method specified in
the OnItemCommand property of repeater:

public void RepeaterResult_Event(object sender, RepeaterCommandEventArgs e) {
string s = " SSS ";
}

below you can see the content of BSResultTextTemplate.ascx :
<tr>
<td class="nerotesti" width="155"><asp:LinkButton id="CmdVisualizzaReperto" runat="server" CommandName="ItemCommand" CommandArgument=<%#
DataBinder.Eval(Container,"DataItem.ID") %> ><%#
DataBinder.Eval(Container,"DataItem.ID") %></asp:LinkButton></td>
<td class="nerotesti" width="160"><%#
DataBinder.Eval(Container,"DataItem.Culture") %></td>
<td class="nerotesti" width="160"><%#
DataBinder.Eval(Container,"DataItem.Subject") %></td>
<td class="nerotesti" width="60"> </td>
</tr>

Now the problem.... the template is loaded successfully but when I click on one of the linkbutton generated, the method RepeaterResult_Event is not
fired...
on the other side if I insert the code of template directly in the repeater definitition and don't load an external template when I click on one of the linkbutton generated all work fine and the method RepeaterResult_Event is
invoked.

Please have anyone a solution for this?

Thank you.
Antonio.

Nov 19 '05 #2
Thank you Vadivel for your answer but it didn't worked,
as you told me I've inserted this line of code inside InitializeComponent:
this.repeaterResults.ItemCommand += new
System.Web.UI.WebControls.RepeaterCommandEventHand ler(this.RepeaterResult_Event);

and I've removed the OnItemCommand property from the aspx file

where is my mistake?

Thank you.
Antonio.

"Vadivel Kumar" wrote:
What i understood from your code is
your should not specify ItemCommand event in aspx file
it should be in your code-behind file.

Create a reference variable for your repeater (repeaterResults) in your cs
file, and go to InitializeComponent method and add ItemCommand event for
this control. It should work.

Do post if you've more problem.

Vadivel Kumar
http://blogs.wdevs.com/varahe

"Antonio Carpentieri" <An****************@discussions.microsoft.com> wrote
in message news:0A**********************************@microsof t.com...
Hi all,
in my previous post I've wrong typed some tems.. this is the corrected

post.

in a aspx page I have a repeater like this:
<asp:repeater id=repeaterResults runat="server"
OnItemCommand="RepeaterResult_Event">
<HeaderTemplate>
<table width="515" border="0" cellpadding="3" cellspacing="0">
</HeaderTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
<SeparatorTemplate>
<tr><td colspan="4"><hr></td></tr>
</SeparatorTemplate>
</asp:repeater>

in the code behind file I dinamically load the Itemtemplate with this

code:

repeaterResults.DataSource = objPds;
string templateName = "templates/BSResultTextTemplate.ascx";
repeaterResults.ItemTemplate = Page.LoadTemplate(templateName);
repeaterResults.DataBind();

Always in the same code behind file, I've defined the Method specified in
the OnItemCommand property of repeater:

public void RepeaterResult_Event(object sender, RepeaterCommandEventArgs

e)
{
string s = " SSS ";
}

below you can see the content of BSResultTextTemplate.ascx :
<tr>
<td class="nerotesti" width="155"><asp:LinkButton

id="CmdVisualizzaReperto"
runat="server" CommandName="ItemCommand" CommandArgument=<%#
DataBinder.Eval(Container,"DataItem.ID") %> ><%#
DataBinder.Eval(Container,"DataItem.ID") %></asp:LinkButton></td>
<td class="nerotesti" width="160"><%#
DataBinder.Eval(Container,"DataItem.Culture") %></td>
<td class="nerotesti" width="160"><%#
DataBinder.Eval(Container,"DataItem.Subject") %></td>
<td class="nerotesti" width="60"> </td>
</tr>

Now the problem.... the template is loaded successfully but when I click

on
one of the linkbutton generated, the method RepeaterResult_Event is not
fired...
on the other side if I insert the code of template directly in the

repeater
definitition and don't load an external template when I click on one of

the
linkbutton generated all work fine and the method RepeaterResult_Event is
invoked.

Please have anyone a solution for this?

Thank you.
Antonio.


Nov 19 '05 #3
What is the error you're getting?
Can you post the code..
I think that is the lesser way to solve the problem :)
--
Vadivel Kumar
http://blogs.wdevs.com/varahe

"Antonio Carpentieri" <An****************@discussions.microsoft.com> wrote
in message news:0C**********************************@microsof t.com...
Thank you Vadivel for your answer but it didn't worked,
as you told me I've inserted this line of code inside InitializeComponent: this.repeaterResults.ItemCommand += new
System.Web.UI.WebControls.RepeaterCommandEventHand ler(this.RepeaterResult_Ev
ent);
and I've removed the OnItemCommand property from the aspx file

where is my mistake?

Thank you.
Antonio.

"Vadivel Kumar" wrote:
What i understood from your code is
your should not specify ItemCommand event in aspx file
it should be in your code-behind file.

Create a reference variable for your repeater (repeaterResults) in your cs file, and go to InitializeComponent method and add ItemCommand event for
this control. It should work.

Do post if you've more problem.

Vadivel Kumar
http://blogs.wdevs.com/varahe

"Antonio Carpentieri" <An****************@discussions.microsoft.com> wrote in message news:0A**********************************@microsof t.com...
Hi all,
in my previous post I've wrong typed some tems.. this is the corrected

post.

in a aspx page I have a repeater like this:
<asp:repeater id=repeaterResults runat="server"
OnItemCommand="RepeaterResult_Event">
<HeaderTemplate>
<table width="515" border="0" cellpadding="3" cellspacing="0">
</HeaderTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
<SeparatorTemplate>
<tr><td colspan="4"><hr></td></tr>
</SeparatorTemplate>
</asp:repeater>

in the code behind file I dinamically load the Itemtemplate with this

code:

repeaterResults.DataSource = objPds;
string templateName = "templates/BSResultTextTemplate.ascx";
repeaterResults.ItemTemplate = Page.LoadTemplate(templateName);
repeaterResults.DataBind();

Always in the same code behind file, I've defined the Method specified in the OnItemCommand property of repeater:

public void RepeaterResult_Event(object sender, RepeaterCommandEventArgs
e)
{
string s = " SSS ";
}

below you can see the content of BSResultTextTemplate.ascx :
<tr>
<td class="nerotesti" width="155"><asp:LinkButton

id="CmdVisualizzaReperto"
runat="server" CommandName="ItemCommand" CommandArgument=<%#
DataBinder.Eval(Container,"DataItem.ID") %> ><%#
DataBinder.Eval(Container,"DataItem.ID") %></asp:LinkButton></td>
<td class="nerotesti" width="160"><%#
DataBinder.Eval(Container,"DataItem.Culture") %></td>
<td class="nerotesti" width="160"><%#
DataBinder.Eval(Container,"DataItem.Subject") %></td>
<td class="nerotesti" width="60"> </td>
</tr>

Now the problem.... the template is loaded successfully but when I
click on
one of the linkbutton generated, the method RepeaterResult_Event is
not fired...
on the other side if I insert the code of template directly in the

repeater
definitition and don't load an external template when I click on one of the
linkbutton generated all work fine and the method RepeaterResult_Event

is invoked.

Please have anyone a solution for this?

Thank you.
Antonio.


Nov 19 '05 #4
I didn't receive any error, simply the event is not fired... now i've worked
to create a new page with only the essential to reproduce the behaviour:

//****************BEGIN OF TEST.ASPX***************
<%@ Page language="c#" Codebehind="Test.aspx.cs" AutoEventWireup="false"
Inherits="ArtPast.Test" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Test</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 MS_POSITIONING="GridLayout">

<form id="Form1" method="post" runat="server">
<asp:repeater id=repeaterResults runat="server">
<HeaderTemplate>
<table width="515" border="0" cellpadding="3" cellspacing="0">
</HeaderTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
<SeparatorTemplate>
<tr>
<td colspan="4">
<hr>
</td>
</tr>
</SeparatorTemplate>
</asp:repeater>
<asp:Label id=Label1 style="Z-INDEX: 101; LEFT: 616px; POSITION: absolute;
TOP: 40px" runat="server" Width="144px">Label</asp:Label>
</form>

</body>
</HTML>
//****************END OF TEST.ASPX***************

//****************BEGIN OF TEST.ASPX.CS***************
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ArtPast
{
/// <summary>
/// Summary description for Test.
/// </summary>
public class Test : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Repeater repeaterResults;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!Page.IsPostBack)
{
LoadResults();
}
}

#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.repeaterResults.ItemCommand += new
System.Web.UI.WebControls.RepeaterCommandEventHand ler(this.repeaterResults_ItemCommand);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void LoadResults()
{
ArrayList lots = new ArrayList();
lots.Add(new Lot(1,"First"));
lots.Add(new Lot(2,"Second"));
lots.Add(new Lot(3,"Third"));
lots.Add(new Lot(4,"Fourth"));
PagedDataSource objPds = new PagedDataSource();
objPds.AllowPaging = true;
objPds.PageSize = 5;
objPds.DataSource = lots;
objPds.CurrentPageIndex = 0;

repeaterResults.DataSource = objPds;
string templateName = "";
templateName = "templates/BSResultTextTemplateTest.ascx";
repeaterResults.ItemTemplate = Page.LoadTemplate(templateName);
repeaterResults.DataBind();
}

private void repeaterResults_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
Label1.Text = "It worked!";
}

protected class Lot
{
private int iD;
private string description;
public Lot(int ID, string Description)
{
iD = ID;
description = Description;
}
public int ID
{
get {return iD;}
set {iD = value;}
}
public string Description
{
get {return description;}
set {description = value;}
}
}
}
}
//****************END OF TEST.ASPX.CS***************

//****************BEGIN OF bSResultTextTemplateTest.ascx***************
<tr>
<td width="155"><asp:LinkButton id="CmdVisualizzaReperto" runat="server"
CommandName="ItemCommand" CommandArgument=<%#
DataBinder.Eval(Container,"DataItem.ID") %> ><%#
DataBinder.Eval(Container,"DataItem.ID") %></asp:LinkButton></td>
<td width="160"><%# DataBinder.Eval(Container,"DataItem.ID") %></td>
<td width="160"><%# DataBinder.Eval(Container,"DataItem.Description") %></td>
<td width="60"> </td>

</tr>
//****************END OF BSResultTextTemplateTest.ascx***************

"Vadivel Kumar" wrote:
What is the error you're getting?
Can you post the code..
I think that is the lesser way to solve the problem :)
--
Vadivel Kumar
http://blogs.wdevs.com/varahe

"Antonio Carpentieri" <An****************@discussions.microsoft.com> wrote
in message news:0C**********************************@microsof t.com...
Thank you Vadivel for your answer but it didn't worked,
as you told me I've inserted this line of code inside

InitializeComponent:
this.repeaterResults.ItemCommand += new

System.Web.UI.WebControls.RepeaterCommandEventHand ler(this.RepeaterResult_Ev
ent);

and I've removed the OnItemCommand property from the aspx file

where is my mistake?

Thank you.
Antonio.

"Vadivel Kumar" wrote:
What i understood from your code is
your should not specify ItemCommand event in aspx file
it should be in your code-behind file.

Create a reference variable for your repeater (repeaterResults) in your cs file, and go to InitializeComponent method and add ItemCommand event for
this control. It should work.

Do post if you've more problem.

Vadivel Kumar
http://blogs.wdevs.com/varahe

"Antonio Carpentieri" <An****************@discussions.microsoft.com> wrote in message news:0A**********************************@microsof t.com...
> Hi all,
> in my previous post I've wrong typed some tems.. this is the corrected
post.
>
> in a aspx page I have a repeater like this:
> <asp:repeater id=repeaterResults runat="server"
> OnItemCommand="RepeaterResult_Event">
> <HeaderTemplate>
> <table width="515" border="0" cellpadding="3" cellspacing="0">
> </HeaderTemplate>
> <FooterTemplate>
> </table>
> </FooterTemplate>
> <SeparatorTemplate>
> <tr><td colspan="4"><hr></td></tr>
> </SeparatorTemplate>
> </asp:repeater>
>
> in the code behind file I dinamically load the Itemtemplate with this
code:
>
> repeaterResults.DataSource = objPds;
> string templateName = "templates/BSResultTextTemplate.ascx";
> repeaterResults.ItemTemplate = Page.LoadTemplate(templateName);
> repeaterResults.DataBind();
>
> Always in the same code behind file, I've defined the Method specified in > the OnItemCommand property of repeater:
>
> public void RepeaterResult_Event(object sender, RepeaterCommandEventArgs e)
> {
> string s = " SSS ";
> }
>
> below you can see the content of BSResultTextTemplate.ascx :
> <tr>
> <td class="nerotesti" width="155"><asp:LinkButton
id="CmdVisualizzaReperto"
> runat="server" CommandName="ItemCommand" CommandArgument=<%#
> DataBinder.Eval(Container,"DataItem.ID") %> ><%#
> DataBinder.Eval(Container,"DataItem.ID") %></asp:LinkButton></td>
> <td class="nerotesti" width="160"><%#
> DataBinder.Eval(Container,"DataItem.Culture") %></td>
> <td class="nerotesti" width="160"><%#
> DataBinder.Eval(Container,"DataItem.Subject") %></td>
> <td class="nerotesti" width="60"> </td>
> </tr>
>
> Now the problem.... the template is loaded successfully but when I click on
> one of the linkbutton generated, the method RepeaterResult_Event is not > fired...
> on the other side if I insert the code of template directly in the
repeater
> definitition and don't load an external template when I click on one of the
> linkbutton generated all work fine and the method RepeaterResult_Event is > invoked.
>
> Please have anyone a solution for this?
>
> Thank you.
> Antonio.
>


Nov 19 '05 #5

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

Similar topics

0
by: Ross | last post by:
Hi I am using the datagrid OnItemCommand to fire an event to remove a cell. e.Item.Cells.RemoveAt(7) e.Item.Cells.ColumnSpan = 2; Which works fine first time through but when I submit a...
1
by: Mukund Patel | last post by:
Hi friends, My repeater's OnItemCommand event executed if I used Link button. But it cannt call by button (<asp:button ... />)> How to execute OnItemCommand event by button in repeater? ...
0
by: Antonio Carpentieri | last post by:
Hi all, in a aspx page I have a repeater like this: <asp:repeater id=repeaterResults runat="server" OnItemCommand="RepeaterResult_Event"> <HeaderTemplate> <table width="515" border="0"...
4
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a...
0
by: rioka | last post by:
I'm going to display data with a repeater control, and each row can have a different layout depending on the value of a column: for example, if column A contains value "1" I want to display Column...
2
by: Jeff | last post by:
Hey asp.net 2.0 I have a Repeater control consisting of linkbuttons on my webpage. when a linkbutton is clicked I need to get the info about the linkbutton clicked and put that info in a...
0
by: rn5a | last post by:
The OnItemCommand in a DataList is raised whenever a Button is clicked in the DataList. Assume that a DataList displays 3 columns & the <HeaderTemplatecontains 3 LinkButtons - one for each column...
0
by: btg | last post by:
We have a situation where some html content is generated and stored in a xxx.aspx file. When we need to show that content, we copy this file to a file called loadtemplate.aspx and then use that...
2
by: RN1 | last post by:
Consider the following code: ------------------------------ <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then 'binding data from...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.