469,898 Members | 1,583 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

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 5474
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 this site, you agree to our Privacy Policy and Terms of Use.