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

M

Magnus Blomberg

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
 
B

Brock Allen

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"]
 
M

Magnus Blomberg

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 said:
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"]
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
 
M

Magnus Blomberg

This question has a new node with Subject "Set a value to a hidden field in
a web page"
/Magnus


Brock Allen said:
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"]
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
 

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

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top