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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    #1

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

    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,fo o4.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!
  • Andrew Thompson

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

    On 13 Nov 2004 12:47:07 -0800, Mike wrote:
    [color=blue]
    > ...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.[/color]

    Include the data in a hidden form field or use CSS to hide the
    textfield. The former is more reliable since it will work for
    people who need to apply a user stylesheet.

    HTH

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane

    Comment

    • Scott Orsburn

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

      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.

      Mike wrote:
      [color=blue]
      >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,fo o4.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!
      >
      >[/color]

      Comment

      Working...