How do I pass data back to my code behind events w/o postback?

M

Mike

I have an ASP.NET webform that has an HTML button (with an onClick
event that calls a javascript function) and a Web Forms button (the
code behind click event saves data back to a SQL DB).

The javascript function basically creates a variable such as:

var someStrings = "foo1.jpg,foo2.jpg,foo3.jpg,foo4.jpg"

I really need to be able to access this javascript variable from the
Click event of my Web Forms button so that I can pull the file names
out of this string and do some database work on them.

Any ideas? I've thought of putting a web forms textbox on the form
and having my javascript function place the string contents in there
which is easily accessible by my web forms button click event, however
now I have an unsightly textbox that should not be on my form.

Is there an easier way to access the contents of a javascript
(client-side) variable from the click event of my web forms button?

Thanks!
 
S

Scott Orsburn

I am not an ASP programmer but have had a similar need using other
technologies.

Unless I am failing to understand what you want to do you could also
have ASP create the JavaScript variable for you. You could certainly
store the strings in a form field, hidden or otherwise, but you could
also do this:

var someStrings = "<% ASP code here to output the strings %>";

The ASP code to generate the strings is executed on the server and will
be done before the browser reads in the JavaScript code your ASP code
generated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top