Monday, March 26, 2012

html form POST to aspx page, then to SQL db

I have a simple little HTML form consisting of about 20 checkboxes and one textarea. This will be emailed out to a few people and upon submission will post to an aspx page which will in turn save the results to a SQL database. What is the best/easiest way to accomplish this? I don't have a problem accessing the values submitted from the aspx page, but how would I go about getting the names of the checkboxes that were checked and saving the value to the corresponding column in the database? Any help would be appreciated (vb if possible). Thanks much

pass the values by session, querystring and use a stored procedure on the page your posting to... to insert these values into your db

on the button click event
create your session

Session["UserID"] = txtUserName.text; - if html form session["UserID"] = request.form(UserID)
Session["Email"] = txtEmail.text;

then

response.redirect(insert.aspx);

insert.aspx runs the stored procedure that inserts the values into your database.

if you create the session on the button click event the sessions get created before the response.redirect and if your using an asp classic form - put the sessions on that pickup page before you call the stored proc


Hi Welcome to asp.net forum.

This is my understanding of your problem:you have a html page which contains 20 checkboxes and one textarea,and when html page is submitted there is a aspx handle the form data(email,store it into DB ....).

how would I go about getting the names of the checkboxes

I think what you want is to test wheather the checkbox is checked since checkboxes is not dynamically created.And keep in mind unchecked checkboxes' name/value pairs are not submitted.

And Store data into session will be a burden to server.


thanks all for your input... Problem is that the page that has the form is not an aspx page, but rather an html page. The form will actually be inserted into an email and mailed out to about 1,000 recipients. So that being said i can't exactly do any processing on the form, but rather on the landing page. I've never done anything going from an html page to an aspx page, only aspx to aspx so i'm a little lost without having options such as querystring and session, etc... On my landing page (on the html form i have action="LandingPage.aspx"... This is correct, right?) and then I have to do all my processing on LandingPage.aspx. I'm doing this and i'm able to iterate thru the values submitted on the form:

For i As Integer = 0 To Request.Form.Keys.Count - 1

Name: Request.Form.Keys(i) / Value: Request.Form.Item(i)

Next

That works fine... But now how do i get all of my values together so that I can do one big insert to the database? Array? Can I pass an array as a paramater to a stored proc?

Thanks again!


Here's an example of doing a batch select with OPENXML on SQL. Instead of doing a SELECT just replace with your INSERT statement. All you need to do is generate the XML doc, which is quite easy!

http://dennylove.blogspot.com/2006/09/sql-openxml-cool-stuff.html


Can I pass an array as a paramater to a stored proc?

No, you can't pass array directly to a stored proc.

But you can construct string in following way "123,12,3245,234,345" and split is in stored proc.

For details you can take a look at this article:How to pass a list of values or array to SQL Server stored procedure


thanks for everyones input... It helped, but in the end i decided to try something new just for kicks so I didn't really have to worry about passing an array to my stored proc or anything... Ended up using bitmasking which worked out great... Thanks again though.

No comments:

Post a Comment