Connecting Tech Pros Worldwide Forums | Help | Site Map

Set a value to a hidden field in a web page

Magnus Blomberg
Guest
 
Posts: n/a
#1: Nov 19 '05
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("val ue")
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 ...[color=blue]
> Make a hidden field (via Page.RegisterHiddenField) and have the javascript
> write the value to the hidden. In the server, fetch the value via[/color]
Request.Form["YourFieldID"][color=blue]
>
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>
>[color=green]
> > 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("val ue");
> > <% run(s); %>
> > }
> > I think this would be rather common, so maybe I'm missing some basics?
> > Regards Magnus
> >[/color]
>
>
>[/color]




Patrice
Guest
 
Posts: n/a
#2: Nov 19 '05

re: Set a value to a hidden field in a web page


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...[color=blue]
> 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[/color]
file[color=blue]
> 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,[/color]
so[color=blue]
> 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("val ue")
> 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() "[/color]
type=submit[color=blue]
> />
> <asp:Label ID="Label11" Runat="server" Text="Label"></asp:Label>
> <input type=hidden id=hide />
> </body>
> --------------------------------------------------------------------------[/color]
--[color=blue]
> ------------------------------------------------
> "Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message
> news:444437632489320772241920@msnews.microsoft.com ...[color=green]
> > Make a hidden field (via Page.RegisterHiddenField) and have the[/color][/color]
javascript[color=blue][color=green]
> > write the value to the hidden. In the server, fetch the value via[/color]
> Request.Form["YourFieldID"][color=green]
> >
> > -Brock
> > DevelopMentor
> > http://staff.develop.com/ballen
> >
> >
> >[color=darkred]
> > > 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("val ue");
> > > <% run(s); %>
> > > }
> > > I think this would be rather common, so maybe I'm missing some basics?
> > > Regards Magnus
> > >[/color]
> >
> >
> >[/color]
>
>
>[/color]


Patrick Olurotimi Ige
Guest
 
Posts: n/a
#3: Nov 19 '05

re: Set a value to a hidden field in a web page


Magnus what are u trying to do??
Vbscript,C#?????



*** Sent via Developersdex http://www.developersdex.com ***
Magnus Blomberg
Guest
 
Posts: n/a
#4: Nov 19 '05

re: Set a value to a hidden field in a web page


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...[color=blue]
> Controlled envionement ? What is the exact problme you have (you have[/color]
always[color=blue]
> "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[/color]
loads...[color=blue]
> 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...[color=green]
> > Hello!
> >
> > I have a problem when using a hidden field to send a value to the[/color][/color]
server.[color=blue][color=green]
> > 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[/color][/color]
using[color=blue][color=green]
> > 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[/color]
> file[color=green]
> > selected
> > b. The script should update a picture shown (the code below just[/color][/color]
shows[color=blue][color=green]
> > 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,[/color]
> so[color=green]
> > I am doing something wrong.
> > I'm not so used to web developing, so please give me some help here,[/color][/color]
with[color=blue][color=green]
> > 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 =[/color][/color]
document.getElementById("File1").getAttribute("val ue")[color=blue][color=green]
> > 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() "[/color]
> type=submit[color=green]
> > />
> > <asp:Label ID="Label11" Runat="server" Text="Label"></asp:Label>
> > <input type=hidden id=hide />
> > </body>[/color]
>
> --------------------------------------------------------------------------
> --[color=green]
> > ------------------------------------------------
> > "Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message
> > news:444437632489320772241920@msnews.microsoft.com ...[color=darkred]
> > > Make a hidden field (via Page.RegisterHiddenField) and have the[/color][/color]
> javascript[color=green][color=darkred]
> > > write the value to the hidden. In the server, fetch the value via[/color]
> > Request.Form["YourFieldID"][color=darkred]
> > >
> > > -Brock
> > > DevelopMentor
> > > http://staff.develop.com/ballen
> > >
> > >
> > >
> > > > Hello!
> > > >
> > > > I have a client javascript that generates a string (like below).[/color][/color][/color]
This[color=blue][color=green][color=darkred]
> > > > 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("val ue");
> > > > <% run(s); %>
> > > > }
> > > > I think this would be rather common, so maybe I'm missing some[/color][/color][/color]
basics?[color=blue][color=green][color=darkred]
> > > > Regards Magnus
> > > >
> > >
> > >
> > >[/color]
> >
> >
> >[/color]
>
>[/color]


Patrice
Guest
 
Posts: n/a
#5: Nov 19 '05

re: Set a value to a hidden field in a web page


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...[color=blue]
> 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[/color]
get.[color=blue]
> 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[/color]
to[color=blue]
> 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...[color=green]
> > Controlled envionement ? What is the exact problme you have (you have[/color]
> always[color=green]
> > "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[/color]
> loads...[color=green]
> > Try to do not "if (!Ispostback)"...
> >
> > Patrice
> >
> > --
> >
> > "Magnus Blomberg" <magnus.blomberg@skanska.se> a écrit dans le message[/color][/color]
de[color=blue][color=green]
> > news:uTXsgPOQFHA.1528@TK2MSFTNGP09.phx.gbl...[color=darkred]
> > > Hello!
> > >
> > > I have a problem when using a hidden field to send a value to the[/color][/color]
> server.[color=green][color=darkred]
> > > 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[/color][/color]
> using[color=green][color=darkred]
> > > 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[/color]
> > file[color=darkred]
> > > selected
> > > b. The script should update a picture shown (the code below just[/color][/color]
> shows[color=green][color=darkred]
> > > 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[/color][/color][/color]
control,[color=blue][color=green]
> > so[color=darkred]
> > > I am doing something wrong.
> > > I'm not so used to web developing, so please give me some help here,[/color][/color]
> with[color=green][color=darkred]
> > > 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 =[/color][/color]
> document.getElementById("File1").getAttribute("val ue")[color=green][color=darkred]
> > > 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() "[/color]
> > type=submit[color=darkred]
> > > />
> > > <asp:Label ID="Label11" Runat="server" Text="Label"></asp:Label>
> > > <input type=hidden id=hide />
> > > </body>[/color]
> >[/color]
>
> --------------------------------------------------------------------------[color=green]
> > --[color=darkred]
> > > ------------------------------------------------
> > > "Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message
> > > news:444437632489320772241920@msnews.microsoft.com ...
> > > > Make a hidden field (via Page.RegisterHiddenField) and have the[/color]
> > javascript[color=darkred]
> > > > 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).[/color][/color]
> This[color=green][color=darkred]
> > > > > 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("val ue");
> > > > > <% run(s); %>
> > > > > }
> > > > > I think this would be rather common, so maybe I'm missing some[/color][/color]
> basics?[color=green][color=darkred]
> > > > > Regards Magnus
> > > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Closed Thread