Server-side script with input parameter from Client-side script

Discussion in 'ASP .Net' started by Magnus Blomberg, Apr 13, 2005.

  1. Hello!

    I have a client javascript that generates a string (like below). This string should then be used by server code (in this case a function called run).

    <script language=javascript>
    function getpic()
    { string s;
    s = document.getElementById("File1").getAttribute("value");
    <% run(s); %>
    }

    I think this would be rather common, so maybe I'm missing some basics?
    Regards Magnus
     
    Magnus Blomberg, Apr 13, 2005
    #1
    1. Advertising

  2. Magnus Blomberg

    Brock Allen Guest

    Make a hidden field (via Page.RegisterHiddenField) and have the javascript
    write the value to the hidden. In the server, fetch the value via Request.Form["YourFieldID"]

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Hello!
    >
    > I have a client javascript that generates a string (like below). This
    > string should then be used by server code (in this case a function
    > called run).
    >
    > <script language=javascript>
    > function getpic()
    > { string s;
    > s = document.getElementById("File1").getAttribute("value");
    > <% run(s); %>
    > }
    > I think this would be rather common, so maybe I'm missing some basics?
    > Regards Magnus
    >
     
    Brock Allen, Apr 13, 2005
    #2
    1. Advertising

  3. Hello!

    Now, I've tried to use a hidden field but I can't get it to work.
    Below you can see my code in simplyfied versions.

    What I'm trying to do is:
    1. The user browses for a picture at the network from their computer using
    control File1.
    2. The user clickes the button Commit picture (with id CliBtn)
    a. The script is running at the client to get the sharename of the file
    selected
    b. The script should update a picture shown (the code below just shows
    the label with the path)
    c. The code-behind should then save all values in a database.

    The problem appear when I'm trying to set the value to the hide control, so
    I am doing something wrong.
    I'm not so used to web developing, so please give me some help here, with
    code please.

    Regards Magnus
    -------------------------
    Code-behind page in C#
    -------------------------
    void Page_Load(object sender, EventArgs e)
    {
    HtmlInputHidden hide = new HtmlInputHidden();
    hide.ID = "hide";
    hide.Value = "Hidden Text";
    sURL = Request.Form["hide"].ToString();
    Label11.Text = sURL;
    }
    ------------------------
    ..ASPX page
    ------------------------
    <head>
    <title>Untitled Page</title>
    <script language=vbscript>
    function getpicvb()
    dim javatext
    javatext = document.getElementById("File1").getAttribute("value")
    dim fso
    set FSO = CreateObject("Scripting.FileSystemObject")
    dim drive
    set drive =
    FSO.GetDrive(FSO.GetDriveName(FSO.GetAbsolutePathName(javatext)))
    javatext = drive.ShareName
    'hide.value = javatext ' this row doesn't work
    alert(javatext)
    end function
    </script>
    </head>
    <body>
    <input id="File1" type="file" />
    <input id="CliBtn" value="Commit picture" onclick="getpicvb() " type=submit
    />
    <asp:Label ID="Label11" Runat="server" Text="Label"></asp:Label>
    <input type=hidden id=hide />
    </body>
    ----------------------------------------------------------------------------
    ------------------------------------------------
    "Brock Allen" <> wrote in message
    news:...
    > Make a hidden field (via Page.RegisterHiddenField) and have the javascript
    > write the value to the hidden. In the server, fetch the value via

    Request.Form["YourFieldID"]
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    > > Hello!
    > >
    > > I have a client javascript that generates a string (like below). This
    > > string should then be used by server code (in this case a function
    > > called run).
    > >
    > > <script language=javascript>
    > > function getpic()
    > > { string s;
    > > s = document.getElementById("File1").getAttribute("value");
    > > <% run(s); %>
    > > }
    > > I think this would be rather common, so maybe I'm missing some basics?
    > > Regards Magnus
    > >

    >
    >
    >
     
    Magnus Blomberg, Apr 14, 2005
    #3
  4. This question has a new node with Subject "Set a value to a hidden field in
    a web page"
    /Magnus


    "Brock Allen" <> wrote in message
    news:...
    > Make a hidden field (via Page.RegisterHiddenField) and have the javascript
    > write the value to the hidden. In the server, fetch the value via

    Request.Form["YourFieldID"]
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    > > Hello!
    > >
    > > I have a client javascript that generates a string (like below). This
    > > string should then be used by server code (in this case a function
    > > called run).
    > >
    > > <script language=javascript>
    > > function getpic()
    > > { string s;
    > > s = document.getElementById("File1").getAttribute("value");
    > > <% run(s); %>
    > > }
    > > I think this would be rather common, so maybe I'm missing some basics?
    > > Regards Magnus
    > >

    >
    >
    >
     
    Magnus Blomberg, Apr 14, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shawn Mehaffie
    Replies:
    4
    Views:
    673
    Shawn Mehaffie
    Jan 22, 2004
  2. =?Utf-8?B?RHVzdGluIElJLg==?=

    Calling a client side script from server side.

    =?Utf-8?B?RHVzdGluIElJLg==?=, Aug 13, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    7,962
    Levi Rosol
    Aug 16, 2004
  3. Mortar
    Replies:
    4
    Views:
    2,251
    Mortar
    Jan 25, 2005
  4. =?Utf-8?B?TWlrZSBSYW5k?=

    Adding Server Side code in a Client Side Script???

    =?Utf-8?B?TWlrZSBSYW5k?=, Jan 30, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,157
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jan 30, 2006
  5. Boss302
    Replies:
    0
    Views:
    1,056
    Boss302
    Nov 21, 2006
Loading...

Share This Page