468,719 Members | 1,778 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,719 developers. It's quick & easy.

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 1719
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Ross | last post: by
1 post views Thread by Mukund Patel | last post: by
reply views Thread by Antonio Carpentieri | last post: by
4 posts views Thread by Jeff User | last post: by
reply views Thread by rioka | last post: by
2 posts views Thread by Jeff | last post: by
reply views Thread by rn5a | last post: by
reply views Thread by btg | last post: by
2 posts views Thread by RN1 | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Oskars | last post: by
9 posts views Thread by bryonone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.