Wednesday, March 21, 2012

passing a Guid to a button class

Hi i have a linkbutton created with C# that needs to call a class and pass a guid through to that class i have tried to use

public void buttonClass(string guid,object sender,Eventargs e)
but it does work i get an error so how do i pass a guid to this class form my button ( code below)

1//button class2public void prodAdd(object sender, EventArgs e)3 {4 checkoutFunctions cartAdd =new checkoutFunctions();5string userGuid = cartAdd.userFind(HttpContext.Current.User.Identity.Name);6 cartAdd.addItem(prodGuid, userGuid);7 Response.Redirect("cart.aspx");8 }910// BUtton generator11 mediaSelect.Controls.Add(new LiteralControl("<a href='#' onClick=\"flashshowHide('" + mediaId + "')\">" + medRead["media_name"].ToString().Replace("#@dotnet.itags.org.","'") +"<span class='prevBut'>(preview)</span></a>"));12 Button buyProd =new Button();13 buyProd.Text = ("Download for £" + medRead["media_price"].ToString());14 buyProd.Click +=new EventHandler(prodAdd);15 mediaSelect.Controls.Add(buyProd);16 mediaSelect.Controls.Add(new LiteralControl("<br/>"));
Thanks
Dan 

I think you must be missing something here conceptually. The prodAdd isnt a button class, it's an event handler that you're wiring up to handle the click event of your dynamically created button. That set of code will run only when the button is clicked. If you need to pass a GUID to it, pass it from wherever it was clicked at, not when the button is created.


yes ok but how do i set it to send the guid to the class when it is clicked


It's not a class - it's an event handler. You are going to have issues till you can get your terminology correct.

Try

buyProd.commandArgument = yourGUID

then in your event handler you can get the guid by using

e.commandArgument

0 comments:

Post a Comment