User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 391,897 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,555 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 3352 | Replies: 10
Reply
Join Date: Jun 2005
Posts: 50
Reputation: Naters_uk is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Naters_uk Naters_uk is offline Offline
Junior Poster in Training

Troubleshooting URGENT!: Saving Database information from ASP.NET Button

  #1  
Jan 13th, 2006
I am working on a seat selection page for an ASP.NET school project on movie booking system. I have created the seats using buttons (A1, A2, A3) etc.

When the user click on the button, the button colour changes and the user finalized the payment. I have an issue here. How do i save the button that has been clicked as an information into SQL Database. For instance, when the user selects Button A1 and A2, i want the information that the users have selected these 2 seats, A1 and A2 into the sql database.

URGENT!!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2006
Location: Its the internet... i am everywhere lol
Posts: 274
Reputation: f1 fan is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 10
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: URGENT!: Saving Database information from ASP.NET Button

  #2  
Jan 13th, 2006
first of all what may be URGENT to you (ie your homework) is not urgent to us. Everyone feels their problem is #1 priority so please dont post as URGENT. My business and income is far more urgent than your homework. But we are here to help so here goes

First of all have one click handler for all the seat buttons. Secondly for each button append the seat number (A1, A2 etc) to the command argument property. On the button click handler grab the argument property and store it in a session object. Then when the whole transaction is complete save the information in the session object. I would recommend either an array or table as the session object.
I assume that:
1. You know about the commandargument property
2. You know about sessions
3. You know how to handle the same eventtype (e.g. buttonclick) from multiple instances in one handler
4. You know how to save information in a database

If you dont know any of those then shout and i will help
Reply With Quote  
Join Date: Jan 2006
Location: Its the internet... i am everywhere lol
Posts: 274
Reputation: f1 fan is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 10
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: URGENT!: Saving Database information from ASP.NET Button

  #3  
Jan 13th, 2006
One line in my last post maybe misleading:

Then when the whole transaction is complete save the information in the session object

Should have said
Then when the whole transaction is complete save the information from the session object
Reply With Quote  
Join Date: Jun 2005
Posts: 50
Reputation: Naters_uk is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Naters_uk Naters_uk is offline Offline
Junior Poster in Training

Re: URGENT!: Saving Database information from ASP.NET Button

  #4  
Jan 15th, 2006
You have made too much assumptions. I think it will be better if u explain with some codes. Thanks

Originally Posted by f1 fan
One line in my last post maybe misleading:



Should have said
Reply With Quote  
Join Date: Jan 2006
Location: Its the internet... i am everywhere lol
Posts: 274
Reputation: f1 fan is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 10
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: URGENT!: Saving Database information from ASP.NET Button

  #5  
Jan 15th, 2006
i will give some pointers... i am not doing homework for you.
each button needs to be setup as follows:
<asp:Button ID="Button1" runat="server" OnClick="SeatButton_Click" Text="A1" CommandArgument="A1" />
<asp:Button ID="Button2" runat="server" OnClick="SeatButton_Click" Text="A2" CommandArgument="A2" />
etc etc

Then you need the one event handler which will handle all your seat buttons
 protected void SeatButton_Click(object sender, EventArgs e)
{
Button theButton = (Button)sender; //now you have the button that was pressed
string theSeat = theButton.CommandArgument; // now you have the seat number

//either store it in the session and the database on some other buttons click (such as a "Book Now" button) or straight to the database on each click.. that depends on your requirements
}
Reply With Quote  
Join Date: Jun 2005
Posts: 50
Reputation: Naters_uk is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Naters_uk Naters_uk is offline Offline
Junior Poster in Training

Re: URGENT!: Saving Database information from ASP.NET Button

  #6  
Jan 16th, 2006
Thanks, i understood the command argument part. However, i am still having problem understanding the second hald as below.



Then you need the one event handler which will handle all your seat buttons
 protected void SeatButton_Click(object sender, EventArgs e)
{
Button theButton = (Button)sender; //now you have the button that was pressed
string theSeat = theButton.CommandArgument; // now you have the seat number

//either store it in the session and the database on some other buttons click (such as a "Book Now" button) or straight to the database on each click.. that depends on your requirements
}
[/quote]
Reply With Quote  
Join Date: Jun 2005
Posts: 50
Reputation: Naters_uk is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Naters_uk Naters_uk is offline Offline
Junior Poster in Training

Re: URGENT!: Saving Database information from ASP.NET Button

  #7  
Jan 16th, 2006
I notice that this half seems to be explained in C#, however i am writing my codes in VB.NET. Would appreciate if you help me with this..

Then you need the one event handler which will handle all your seat buttons
 protected void SeatButton_Click(object sender, EventArgs e)
{
Button theButton = (Button)sender; //now you have the button that was pressed
string theSeat = theButton.CommandArgument; // now you have the seat number

//either store it in the session and the database on some other buttons click (such as a "Book Now" button) or straight to the database on each click.. that depends on your requirements
}
[/quote]
Reply With Quote  
Join Date: Jun 2005
Posts: 50
Reputation: Naters_uk is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Naters_uk Naters_uk is offline Offline
Junior Poster in Training

Re: URGENT!: Saving Database information from ASP.NET Button

  #8  
Jan 16th, 2006
I have referred to this website,

http://www.startvbdotnet.com/aspsite...ls/button.aspx

i still can't figure out the difference between CommandArgument property and CommandName property
Reply With Quote  
Join Date: Jan 2006
Location: Its the internet... i am everywhere lol
Posts: 274
Reputation: f1 fan is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 10
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: URGENT!: Saving Database information from ASP.NET Button

  #9  
Jan 16th, 2006
the command name property could be used in your case but it is a bad habit to get into. The command name property is used when the button is used inside something like a datalist. You can have many buttons in various templates and they will want to do various things (such as Edit, cancel, update etc). The parent control (eg the datalist) handles these controls not the page so you have to tell the parent what type of command it is (hence commandname = "edit" or commandname = "update") and you have an event handler for the parent control in your code. As there are multiple versions of this button in a datalist control you might need to pass extra info to the event handler - this is where the commandargument comes in. The concept is the same as calling a method and passing in parameters.
So stick to the rule that command name = method name and command argument = parameters. So you can pass parameters even though you dont need a method name in this case as the handler is already named in the onclick property.

As for the code my vb is very rusty but i will try
protected sub SeatButton_Click(object sender, EventArgs e) handles Seatbutton_click

Dim theButton as Button  = Ctype(sender, Button) ' now you have the button that was pressed
Dim theSeat as string  = theButton.CommandArgument; ' now you have the seat number

' either store it in the session and the database on some other buttons click (such as a "Book Now" button) or straight to the database on each click.. that depends on your requirements
End Sub
Reply With Quote  
Join Date: Jun 2005
Posts: 50
Reputation: Naters_uk is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Naters_uk Naters_uk is offline Offline
Junior Poster in Training

Re: URGENT!: Saving Database information from ASP.NET Button

  #10  
Jan 19th, 2006
Sorry to bother you again. How can i store all the information (all the button clicks) as a session into the database
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP.NET Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 7:26 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC