473,395 Members | 2,713 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,395 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 1928
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: 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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.