473,379 Members | 1,184 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,379 software developers and data experts.

OnCommand Problem with Linkbutton as a TemplateItem

Hi All,

I have a Repeater that contains a LinkButton as one of the items in the
ItemTemplate. I have the OnCommand (method is called "messageActions")
and CommandName ("view") properties set, as well as a CommandArgument
for the LinkButton to fire off when clicked. For some reason, when I
try to set the CommandEventHandler for the LinkButton:

this.messageSubject.Command += new CommandEventHandler(messageActions);
I get an object reference runtime error. I have the LinkButton
delcared.

Can someone give me an example on the correct way to set this up so my
method will fire? My code snippet is below. Thanks so much in advance!

<asp:Repeater ID="messageRepeater" Runat="server">
<ItemTemplate>
<asp:LinkButton ID="messageSubject" OnCommand="messageActions"
CommandName="view" CommandArgument='<%#
DataBinder.Eval(Container.DataItem,"Id") %>' Runat="server"><%#
DataBinder.Eval(Container.DataItem,"MessageSubject ")
%></asp:LinkButton>
</ItemTemplate>

protected void messageActions(Object sender, CommandEventArgs e)
{
string command = e.CommandName;
switch (command)
{
(do something)
}
}

Nov 14 '06 #1
0 1307

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

Similar topics

0
by: Vik | last post by:
Is it possible to set OnCommand property of a button programmatically? I tried btn.Attributes.Add("OnCommand", "MySub") but this doesn't work. Thanks.
0
by: Vik | last post by:
Is it possible to set OnCommand property of a button in run time? I tried MyBtn.Attributes.Add("OnCommand", "MySub") but it does not work. Thanks.
1
by: Thanks | last post by:
I have a routine that is called on Page_Init. It retrieves folder records from a database which I display as Link Buttons in a table cell. I set the table cell's bgcolor to a default color (say...
2
by: Matthew MacDonald | last post by:
Hi all, I am adding controls to a table dynamically. I have a list that I am putting into the session to keep track of them on postback. What I need to know though, is how to add the oncommand...
1
by: Sheryl Landon | last post by:
Is there a way to set the OnCommand or OnClick attributes when adding a LinkButton dynamically through code? These attributes are available when adding on design-time... Thanks, Sheryl
0
by: tafpin | last post by:
I have an application with a datagrid. In the IDE I have 2 template columns. The first has an image button and the second contains a link button. According to the results that I get back I must...
0
by: Sam | last post by:
I am trying to use a Simple form with 3 fields from SQL NorthWind Database (Order Details Table with 3 Fields. - OrderId, ProductId and Unit Price). The Field Unit Price has a data type of 'Money...
2
by: Roy | last post by:
Hey all, This is so silly I can't believe I'm even asking, but I've never had it come up before in my work. How do I place a string within the parantheses in the popup_command() call below?...
0
by: clintonG | last post by:
A Matter of Design: OnCommand or OnClick Event Handler? Attributing a control using OnCommand supports the use of other attibutes such as CommandName and CommandArgument. AFIK OnClick does not....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.