dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: ASP.NET
Expertise: Beginner
Mar 17, 2009

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Pass Arguments to Subroutines from a Button Control

You can use the CommandName and CommandArgument attributes of a button to submit arguments to an ASP.NET method on the server. For example, suppose you have a repeater control in a page that shows a nicely formatted list of products. You can include a button on that page that, when clicked, calls a subroutine to add the product to the user's shopping cart.

Rather than writing functions to get the product ID and name, or query the database to get that information, you can set the Button's CommandName property to the name of the product and its CommandArgument property to the product ID. You can even use comma-separated values if you need more than two values (although in that case it would probably make more sense to go back to the database). Here's a simplified example just to show how it works.

First, here's the Button code:

   
And here's the server code:

   Public Sub AddToCart(sender As Object, e As CommandEventArgs)
       Session("currentCart") = Session("currentCart") & _
           e.CommandName & "," & e.CommandArgument & ";"
   End Sub
When the user clicks the button, you can retrieve the CommandName and CommandArgument values from the CommandEventArgs parameter defined in the AddToCart method.

Cindy Rodriguez
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date