Saturday, March 31, 2012

Set a value to a hidden field in a web page

Hello!

I have a problem when using a hidden field to send a value to the server.
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.GetAbsolutePathN ame(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" <ballen@dotnet.itags.org.NOSPAMdevelop.com> wrote in message
news:444437632489320772241920@dotnet.itags.org.msnews.microsoft.com ...
> 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 MagnusControlled envionement ? What is the exact problme you have (you have always
"Hidden Text" server side ?

In particular fso is not supposed to work without tweaking security
settings. ARe you sure itjust doesn't fails silently...
Also you always change the value of the "hide" field when the page loads...
Try to do not "if (!Ispostback)"...

Patrice

--

"Magnus Blomberg" <magnus.blomberg@.skanska.se> a crit dans le message de
news:uTXsgPOQFHA.1528@.TK2MSFTNGP09.phx.gbl...
> Hello!
> I have a problem when using a hidden field to send a value to the server.
> 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.GetAbsolutePathN ame(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" <ballen@.NOSPAMdevelop.com> wrote in message
> news:444437632489320772241920@.msnews.microsoft.com ...
> > 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 what are u trying to do??
Vbscript,C#???

*** Sent via Developersdex http://www.developersdex.com ***
Hello and thanks for your answer.
Well, I thought fso was not a common way to solve this, but since this is
for a Intranet, I think I can theak the security anyway. If you have a
better solution for this issue I'll be glad to here it.
I'm not sure what silent failure does mean, but I think that is what I get.
I get no error message, but the alert row is never executed when the
hide.value = javatext is run.

The problem does not appear when working with fso. It appears when trying to
set the hide object.

I am familiar to the (!IsPostBack) command, so I will take care of that in
my full code.
My code in this forum is shrinked.

Regards Magnus

"Patrice" <nobody@.nowhere.com> wrote in message
news:#Xio4aOQFHA.3076@.TK2MSFTNGP14.phx.gbl...
> Controlled envionement ? What is the exact problme you have (you have
always
> "Hidden Text" server side ?
> In particular fso is not supposed to work without tweaking security
> settings. ARe you sure itjust doesn't fails silently...
> Also you always change the value of the "hide" field when the page
loads...
> Try to do not "if (!Ispostback)"...
> Patrice
> --
> "Magnus Blomberg" <magnus.blomberg@.skanska.se> a crit dans le message de
> news:uTXsgPOQFHA.1528@.TK2MSFTNGP09.phx.gbl...
> > Hello!
> > I have a problem when using a hidden field to send a value to the
server.
> > 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.GetAbsolutePathN ame(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" <ballen@.NOSPAMdevelop.com> wrote in message
> > news:444437632489320772241920@.msnews.microsoft.com ...
> > > 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
> > > > >
Ok, so this line is never executed.

Check if the fso object is set. Do you have yet tweaked security ?

If I remember when security is not tweaked , it fails without any warning
(as anyway it 's not supposed to work).

What do you want to do ? You can use an input type=file to get the name
server side even if you don't want to upload this file. This way you
wouldn't need to copy this value in an hidden field.

Also I don't really see how it works. The server could perhaps not have the
same netwrok path available.

Depneidng on what you wan to do with this file, I would upload it server
file to do the intended processing...

Good luck

Patrice

--

"Magnus Blomberg" <magnus.blomberg@.skanska.se> a crit dans le message de
news:%23GCvfKPQFHA.3988@.tk2msftngp13.phx.gbl...
> Hello and thanks for your answer.
> Well, I thought fso was not a common way to solve this, but since this is
> for a Intranet, I think I can theak the security anyway. If you have a
> better solution for this issue I'll be glad to here it.
> I'm not sure what silent failure does mean, but I think that is what I
get.
> I get no error message, but the alert row is never executed when the
> hide.value = javatext is run.
> The problem does not appear when working with fso. It appears when trying
to
> set the hide object.
> I am familiar to the (!IsPostBack) command, so I will take care of that in
> my full code.
> My code in this forum is shrinked.
> Regards Magnus
>
> "Patrice" <nobody@.nowhere.com> wrote in message
> news:#Xio4aOQFHA.3076@.TK2MSFTNGP14.phx.gbl...
> > Controlled envionement ? What is the exact problme you have (you have
> always
> > "Hidden Text" server side ?
> > In particular fso is not supposed to work without tweaking security
> > settings. ARe you sure itjust doesn't fails silently...
> > Also you always change the value of the "hide" field when the page
> loads...
> > Try to do not "if (!Ispostback)"...
> > Patrice
> > --
> > "Magnus Blomberg" <magnus.blomberg@.skanska.se> a crit dans le message
de
> > news:uTXsgPOQFHA.1528@.TK2MSFTNGP09.phx.gbl...
> > > Hello!
> > > > I have a problem when using a hidden field to send a value to the
> server.
> > > 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.GetAbsolutePathN ame(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" <ballen@.NOSPAMdevelop.com> wrote in message
> > > news:444437632489320772241920@.msnews.microsoft.com ...
> > > > 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
> > > > > > > > > > > >

0 comments:

Post a Comment