Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > C# linkbutton question object does not contain a definition for CommandArgument

Reply
Thread Tools

C# linkbutton question object does not contain a definition for CommandArgument

 
 
needin4mation@gmail.com
Guest
Posts: n/a
 
      10-12-2005
I have some VB.NET code that I am trying to convert. I'm not sure what
to do here and was hoping you could help.

Sub PagerButtonClick(sender As Object, e As EventArgs)
'used by external paging UI
Dim arg As String = sender.CommandArgument

is the code from:

http://www.4guysfromrolla.com/webtech/082901-1.2.shtml

I have tried this code in c# (converted as best I could) but I cannot
get the sender.CommandArgument to work.

It's just a button that calls a function on the server side. This
signature:

object sender, System.EventArgs e

does not have an CommandArgument.

I tried a cast like:

(System.Web.UI.WebControls.DataGridCommandEventArg s) sender, but it has
no effect.

I don't know what to do. Thank you for any help. How can I access the
command argument of a button that is not in the datagrid?

 
Reply With Quote
 
 
 
 
Elton Wang
Guest
Posts: n/a
 
      10-12-2005
CommandArgument should come from EventArgs rather than from Object. Try

Dim arg As String = e.CommandArgument

HTH



<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
>I have some VB.NET code that I am trying to convert. I'm not sure what
> to do here and was hoping you could help.
>
> Sub PagerButtonClick(sender As Object, e As EventArgs)
> 'used by external paging UI
> Dim arg As String = sender.CommandArgument
>
> is the code from:
>
> http://www.4guysfromrolla.com/webtech/082901-1.2.shtml
>
> I have tried this code in c# (converted as best I could) but I cannot
> get the sender.CommandArgument to work.
>
> It's just a button that calls a function on the server side. This
> signature:
>
> object sender, System.EventArgs e
>
> does not have an CommandArgument.
>
> I tried a cast like:
>
> (System.Web.UI.WebControls.DataGridCommandEventArg s) sender, but it has
> no effect.
>
> I don't know what to do. Thank you for any help. How can I access the
> command argument of a button that is not in the datagrid?
>



 
Reply With Quote
 
 
 
 
needin4mation@gmail.com
Guest
Posts: n/a
 
      10-13-2005
I won't work as EventArgs or sender. There is no CommandArgument for
object or System.EventArgs. The VB Code allows it, but not the C# code.

 
Reply With Quote
 
swati254 swati254 is offline
Junior Member
Join Date: May 2008
Posts: 11
 
      12-23-2008
generally this error occured when OnClick=LinkButton1_click instead of LinkButton_Click.i.e. C should be capital in Click.

<asp:LinkButton ID="lbtndetails" CssClass="offfer-price-button" OnClick="lbtndetails_Click" runat="server" CommandName="viewdetails" CommandArgument='<%#DataBinder.Eval(Container.Data Item, "ProductID") %>' >Details</asp:LinkButton>

Second thing is
u can get commandArgument value as follows:

protected void lbtndetails_Click(object sender, EventArgs e)
{
LinkButton mybutton1 = sender as LinkButton;
if (mybutton1 != null)
{
string info = mybutton1.CommandArgument;

Session["pid"] = info;
Response.Redirect("ProductDetail.aspx");
//Response.Write(info);
}

}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does string contain A, and if so, does a section of string contain B Jason Carlton Javascript 11 12-08-2009 06:07 PM
LinkButton does not contain definition beacon123 ASP .Net 0 09-17-2009 08:34 PM
CommandArgument does not contain index when under Templatefield?? jobs ASP .Net 1 02-14-2007 01:03 PM
commandargument in linkbutton Question Patrick Olurotimi Ige ASP .Net 0 06-20-2005 08:08 AM
LinkButton CommandArgument bound property loses value on postback =?Utf-8?B?QmVuamFtaW4gSm9sZGVyc21h?= ASP .Net 2 08-21-2004 05:57 PM



Advertisments