472,142 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

How to pass argument in image button's click handler

I am developing a shopping cart application for jwellary designing \
now i am displaying all the product in the table dynamically.
and also show on image button as a add to cart after every item.
now when ever client clicks on the add to cart button than i want the
item id no in the button's click event's how can be it possible.

Here i show the code

System.Web.UI.WebControls.ImageButton add = new
System.Web.UI.WebControls.ImageButton();
add.CssClass = "button";
//add.CommandArgument = c.getRecord(start,
"Prod_ID").ToString();
add.ImageUrl = @"D:\Tarun\Final\Admin\Images\\addtocart4.jpg";
add.Click += new ImageClickEventHandler(btnaddprod_Click);
System.Web.UI.WebControls.Panel p = new
System.Web.UI.WebControls.Panel();
p.Controls.Add(add);
protected void btnaddprod_Click(object sender, EventArgs e)
{
//Dim cmdArg As String = CType(sender,
ImageButton).CommandArgument
//I know above line is working in VB.NET but i want same thing
in C#.NET can anybody helpme
}

Mar 7 '07 #1
1 5732
check into some of the new properties in the button control ('OnCommand',
'CommandName', and 'CommandArgument'). 'OnCommand' is used in place of the
'OnClick' property. Then, we can use any combination of 'CommandName' and
'CommandArgument' in the shared subroutine (or event handler), to process
the event.

--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://aspexpress.com
"TarDuk a memory beyond the life" <ta*************@gmail.comwrote in
message news:11**********************@q40g2000cwq.googlegr oups.com...
I am developing a shopping cart application for jwellary designing \
now i am displaying all the product in the table dynamically.
and also show on image button as a add to cart after every item.
now when ever client clicks on the add to cart button than i want the
item id no in the button's click event's how can be it possible.

Here i show the code

System.Web.UI.WebControls.ImageButton add = new
System.Web.UI.WebControls.ImageButton();
add.CssClass = "button";
//add.CommandArgument = c.getRecord(start,
"Prod_ID").ToString();
add.ImageUrl = @"D:\Tarun\Final\Admin\Images\\addtocart4.jpg";
add.Click += new ImageClickEventHandler(btnaddprod_Click);
System.Web.UI.WebControls.Panel p = new
System.Web.UI.WebControls.Panel();
p.Controls.Add(add);
protected void btnaddprod_Click(object sender, EventArgs e)
{
//Dim cmdArg As String = CType(sender,
ImageButton).CommandArgument
//I know above line is working in VB.NET but i want same thing
in C#.NET can anybody helpme
}

Mar 7 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

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.