469,632 Members | 1,698 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,632 developers. It's quick & easy.

Passing data from server side to client side?

Ok, im not sure if this is at all possible and if it is how i go about it is
beyond me

i have a piece of client side code that requires a piece of data from the
server side (an ID number in this case)

how can i pass the data from one side to the other, or retrieve it from the
webform on the client side?

i hope ive explained this properly

Mike Fellows
Nov 18 '05 #1
8 3426
Mike,

This is one of the most common tasks in ASP.NET development. The solution is
to use hidden elements. If you need a single id value, you can use any html
element capable of holding values. If you need to pass the value back, you
need to use a <input type="hidden" ...>. If you need an id column in a grid,
you need to ad a column to your datagrid and make it invisible with a
stylesheet rule.

Note, if you use a server control and set property Visible to false, the
control won't be rendered to the client and you won't get anything.

Eliyahu

"Mike Fellows" <mi***************@equityhouse.co.uk> wrote in message
news:WpbEc.1276$Cs1.434@newsfe6-win...
Ok, im not sure if this is at all possible and if it is how i go about it is beyond me

i have a piece of client side code that requires a piece of data from the
server side (an ID number in this case)

how can i pass the data from one side to the other, or retrieve it from the webform on the client side?

i hope ive explained this properly

Mike Fellows

Nov 18 '05 #2
Eliyahu,

ok i sort of understand (though not fully)

if i have a label on my webform called MyLabel

and i have a clientside HTML button that runs my client side code

i want my HTML button to get the value of MyLabel so that i can use it
clientside

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:u2**************@TK2MSFTNGP10.phx.gbl...
Mike,

This is one of the most common tasks in ASP.NET development. The solution is to use hidden elements. If you need a single id value, you can use any html element capable of holding values. If you need to pass the value back, you
need to use a <input type="hidden" ...>. If you need an id column in a grid, you need to ad a column to your datagrid and make it invisible with a
stylesheet rule.

Note, if you use a server control and set property Visible to false, the
control won't be rendered to the client and you won't get anything.

Eliyahu

"Mike Fellows" <mi***************@equityhouse.co.uk> wrote in message
news:WpbEc.1276$Cs1.434@newsfe6-win...
Ok, im not sure if this is at all possible and if it is how i go about it
is
beyond me

i have a piece of client side code that requires a piece of data from

the server side (an ID number in this case)

how can i pass the data from one side to the other, or retrieve it from

the
webform on the client side?

i hope ive explained this properly

Mike Fellows


Nov 18 '05 #3
That's fine. Give you label an id and refer to it from javascript. If it is
an asp:Label, it will translate to <span> and you can get the label text via
innerText property.

Eliyahu

"Mike Fellows" <mi***************@equityhouse.co.uk> wrote in message
news:s1eEc.1931$Cs1.1084@newsfe6-win...
Eliyahu,

ok i sort of understand (though not fully)

if i have a label on my webform called MyLabel

and i have a clientside HTML button that runs my client side code

i want my HTML button to get the value of MyLabel so that i can use it
clientside

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:u2**************@TK2MSFTNGP10.phx.gbl...
Mike,

This is one of the most common tasks in ASP.NET development. The solution
is
to use hidden elements. If you need a single id value, you can use any

html
element capable of holding values. If you need to pass the value back, you need to use a <input type="hidden" ...>. If you need an id column in a

grid,
you need to ad a column to your datagrid and make it invisible with a
stylesheet rule.

Note, if you use a server control and set property Visible to false, the
control won't be rendered to the client and you won't get anything.

Eliyahu

"Mike Fellows" <mi***************@equityhouse.co.uk> wrote in message
news:WpbEc.1276$Cs1.434@newsfe6-win...
Ok, im not sure if this is at all possible and if it is how i go about it
is
beyond me

i have a piece of client side code that requires a piece of data from

the server side (an ID number in this case)

how can i pass the data from one side to the other, or retrieve it

from the
webform on the client side?

i hope ive explained this properly

Mike Fellows



Nov 18 '05 #4
Eliyahu,

I hate to be a pain, but im probably more confused than ever

could you point me in the direction of an example at all?
(ive tried searching for them but i cant find any)

Thanks

Mike
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ei*************@tk2msftngp13.phx.gbl...
That's fine. Give you label an id and refer to it from javascript. If it is an asp:Label, it will translate to <span> and you can get the label text via innerText property.

Eliyahu

"Mike Fellows" <mi***************@equityhouse.co.uk> wrote in message
news:s1eEc.1931$Cs1.1084@newsfe6-win...
Eliyahu,

ok i sort of understand (though not fully)

if i have a label on my webform called MyLabel

and i have a clientside HTML button that runs my client side code

i want my HTML button to get the value of MyLabel so that i can use it
clientside

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:u2**************@TK2MSFTNGP10.phx.gbl...
Mike,

This is one of the most common tasks in ASP.NET development. The solution
is
to use hidden elements. If you need a single id value, you can use any

html
element capable of holding values. If you need to pass the value back, you need to use a <input type="hidden" ...>. If you need an id column in a

grid,
you need to ad a column to your datagrid and make it invisible with a
stylesheet rule.

Note, if you use a server control and set property Visible to false, the control won't be rendered to the client and you won't get anything.

Eliyahu

"Mike Fellows" <mi***************@equityhouse.co.uk> wrote in message
news:WpbEc.1276$Cs1.434@newsfe6-win...
> Ok, im not sure if this is at all possible and if it is how i go
about it
is
> beyond me
>
> i have a piece of client side code that requires a piece of data
from the
> server side (an ID number in this case)
>
> how can i pass the data from one side to the other, or retrieve it

from the
> webform on the client side?
>
> i hope ive explained this properly
>
> Mike Fellows
>
>



Nov 18 '05 #5
Mike,

Let's say you want to pass hidden id value from server to client.

1. Add a hidden label control to the aspx page:
<asp:Label id="hiddenId" runat="server" CssClass="Hidden"></asp:Label>
Add a stylesheet rule for Hidden to the page: .Hidden{display:none}

2. In the code-behind on server-side assign values to the id:
hiddenId.Text = "12345";

3. In javascripts on client-side get the value:
var id=hiddenId.innerText;

If it is not clear, please tell me what step causes a problem.

Eliyahu

"Mike Fellows" <mi***************@equityhouse.co.uk> wrote in message
news:yweEc.2058$Cs1.739@newsfe6-win...
Eliyahu,

I hate to be a pain, but im probably more confused than ever

could you point me in the direction of an example at all?
(ive tried searching for them but i cant find any)

Thanks

Mike
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ei*************@tk2msftngp13.phx.gbl...
That's fine. Give you label an id and refer to it from javascript. If it

is
an asp:Label, it will translate to <span> and you can get the label text

via
innerText property.

Eliyahu

"Mike Fellows" <mi***************@equityhouse.co.uk> wrote in message
news:s1eEc.1931$Cs1.1084@newsfe6-win...
Eliyahu,

ok i sort of understand (though not fully)

if i have a label on my webform called MyLabel

and i have a clientside HTML button that runs my client side code

i want my HTML button to get the value of MyLabel so that i can use it
clientside

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:u2**************@TK2MSFTNGP10.phx.gbl...
> Mike,
>
> This is one of the most common tasks in ASP.NET development. The

solution
is
> to use hidden elements. If you need a single id value, you can use any html
> element capable of holding values. If you need to pass the value back,
you
> need to use a <input type="hidden" ...>. If you need an id column in
a grid,
> you need to ad a column to your datagrid and make it invisible with a > stylesheet rule.
>
> Note, if you use a server control and set property Visible to false,

the > control won't be rendered to the client and you won't get anything.
>
> Eliyahu
>
> "Mike Fellows" <mi***************@equityhouse.co.uk> wrote in message > news:WpbEc.1276$Cs1.434@newsfe6-win...
> > Ok, im not sure if this is at all possible and if it is how i go about it
> is
> > beyond me
> >
> > i have a piece of client side code that requires a piece of data from the
> > server side (an ID number in this case)
> >
> > how can i pass the data from one side to the other, or retrieve it

from
> the
> > webform on the client side?
> >
> > i hope ive explained this properly
> >
> > Mike Fellows
> >
> >
>
>



Nov 18 '05 #6
Eliyahu,

ok all worked fine on the server side, but i get an error on page on load

im including my code so you can see what im doing, i think the problem lies
within the javascript script

thanks

Mike

<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">

<SCRIPT language="javascript">
var id=hiddenId.innerText
</SCRIPT>

<SCRIPT language="VBScript">
Dim objWord
Dim exists
Sub OpenDoc()
Set objWord = CreateObject("Word.Application")
objWord.Documents.Open("\\Gringotts\common
documents\AutoPackProduction\Remortgage\Factfind.d oc")
objWord.Visible = true
objWord.activedocument.saveas("c:\"& id &".doc")
set objWord=nothing
End Sub
</SCRIPT>

</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
</form>
<input style="Z-INDEX: 101; LEFT: 165px; WIDTH: 157px; POSITION: absolute;
TOP: 82px; HEIGHT: 48px"
onclick="opendoc()" type="button" value="opendoc">&nbsp;
<asp:label id="hiddenId" style="Z-INDEX: 102; LEFT: 50px; POSITION:
absolute; TOP: 28px" runat="server"
CssClass="Hidden"></asp:label>
</body>
</HTML>

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:OG**************@tk2msftngp13.phx.gbl...
Mike,

Let's say you want to pass hidden id value from server to client.

1. Add a hidden label control to the aspx page:
<asp:Label id="hiddenId" runat="server" CssClass="Hidden"></asp:Label>
Add a stylesheet rule for Hidden to the page: .Hidden{display:none}

2. In the code-behind on server-side assign values to the id:
hiddenId.Text = "12345";

3. In javascripts on client-side get the value:
var id=hiddenId.innerText;

If it is not clear, please tell me what step causes a problem.

Eliyahu

"Mike Fellows" <mi***************@equityhouse.co.uk> wrote in message
news:yweEc.2058$Cs1.739@newsfe6-win...
Eliyahu,

I hate to be a pain, but im probably more confused than ever

could you point me in the direction of an example at all?
(ive tried searching for them but i cant find any)

Thanks

Mike
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ei*************@tk2msftngp13.phx.gbl...
That's fine. Give you label an id and refer to it from javascript. If it
is
an asp:Label, it will translate to <span> and you can get the label
text
via
innerText property.

Eliyahu

"Mike Fellows" <mi***************@equityhouse.co.uk> wrote in message
news:s1eEc.1931$Cs1.1084@newsfe6-win...
> Eliyahu,
>
> ok i sort of understand (though not fully)
>
> if i have a label on my webform called MyLabel
>
> and i have a clientside HTML button that runs my client side code
>
> i want my HTML button to get the value of MyLabel so that i can use
it > clientside
>
>
>
>
>
> "Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
> news:u2**************@TK2MSFTNGP10.phx.gbl...
> > Mike,
> >
> > This is one of the most common tasks in ASP.NET development. The
solution
> is
> > to use hidden elements. If you need a single id value, you can use
any > html
> > element capable of holding values. If you need to pass the value back, you
> > need to use a <input type="hidden" ...>. If you need an id column in a
> grid,
> > you need to ad a column to your datagrid and make it invisible
with
a > > stylesheet rule.
> >
> > Note, if you use a server control and set property Visible to
false, the
> > control won't be rendered to the client and you won't get

anything. > >
> > Eliyahu
> >
> > "Mike Fellows" <mi***************@equityhouse.co.uk> wrote in

message > > news:WpbEc.1276$Cs1.434@newsfe6-win...
> > > Ok, im not sure if this is at all possible and if it is how i go

about
> it
> > is
> > > beyond me
> > >
> > > i have a piece of client side code that requires a piece of data

from
> the
> > > server side (an ID number in this case)
> > >
> > > how can i pass the data from one side to the other, or retrieve it from
> > the
> > > webform on the client side?
> > >
> > > i hope ive explained this properly
> > >
> > > Mike Fellows
> > >
> > >
> >
> >
>
>



Nov 18 '05 #7
Mike,

A few things:

You can't have webcontrols outside <form> tags.

The javascript should be a function and you should call it on client-side
load event:
<SCRIPT language="javascript">
var id;
function getId() {id=hiddenId.innerText;}
</SCRIPT>
....
<body MS_POSITIONING="GridLayout" onload="getId()">
After this variable id is available to other javascripts functions on the
page.

Also the stylesheet rule for Hidden is missing, unless you don't want to
hide the id.

Eliyahu

"Mike Fellows" <mi***************@equityhouse.co.uk> wrote in message
news:OyfEc.2307$Cs1.737@newsfe6-win...
Eliyahu,

ok all worked fine on the server side, but i get an error on page on load

im including my code so you can see what im doing, i think the problem lies within the javascript script

thanks

Mike

<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">

<SCRIPT language="javascript">
var id=hiddenId.innerText
</SCRIPT>

<SCRIPT language="VBScript">
Dim objWord
Dim exists
Sub OpenDoc()
Set objWord = CreateObject("Word.Application")
objWord.Documents.Open("\\Gringotts\common
documents\AutoPackProduction\Remortgage\Factfind.d oc")
objWord.Visible = true
objWord.activedocument.saveas("c:\"& id &".doc")
set objWord=nothing
End Sub
</SCRIPT>

</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
</form>
<input style="Z-INDEX: 101; LEFT: 165px; WIDTH: 157px; POSITION: absolute; TOP: 82px; HEIGHT: 48px"
onclick="opendoc()" type="button" value="opendoc">&nbsp;
<asp:label id="hiddenId" style="Z-INDEX: 102; LEFT: 50px; POSITION:
absolute; TOP: 28px" runat="server"
CssClass="Hidden"></asp:label>
</body>
</HTML>

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:OG**************@tk2msftngp13.phx.gbl...
Mike,

Let's say you want to pass hidden id value from server to client.

1. Add a hidden label control to the aspx page:
<asp:Label id="hiddenId" runat="server" CssClass="Hidden"></asp:Label>
Add a stylesheet rule for Hidden to the page: .Hidden{display:none}

2. In the code-behind on server-side assign values to the id:
hiddenId.Text = "12345";

3. In javascripts on client-side get the value:
var id=hiddenId.innerText;

If it is not clear, please tell me what step causes a problem.

Eliyahu

"Mike Fellows" <mi***************@equityhouse.co.uk> wrote in message
news:yweEc.2058$Cs1.739@newsfe6-win...
Eliyahu,

I hate to be a pain, but im probably more confused than ever

could you point me in the direction of an example at all?
(ive tried searching for them but i cant find any)

Thanks

Mike
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ei*************@tk2msftngp13.phx.gbl...
> That's fine. Give you label an id and refer to it from javascript. If
it
is
> an asp:Label, it will translate to <span> and you can get the label text via
> innerText property.
>
> Eliyahu
>
> "Mike Fellows" <mi***************@equityhouse.co.uk> wrote in
message > news:s1eEc.1931$Cs1.1084@newsfe6-win...
> > Eliyahu,
> >
> > ok i sort of understand (though not fully)
> >
> > if i have a label on my webform called MyLabel
> >
> > and i have a clientside HTML button that runs my client side code
> >
> > i want my HTML button to get the value of MyLabel so that i can us e
it > > clientside
> >
> >
> >
> >
> >
> > "Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
> > news:u2**************@TK2MSFTNGP10.phx.gbl...
> > > Mike,
> > >
> > > This is one of the most common tasks in ASP.NET development. The
> solution
> > is
> > > to use hidden elements. If you need a single id value, you can
use
any
> > html
> > > element capable of holding values. If you need to pass the value back,
> you
> > > need to use a <input type="hidden" ...>. If you need an id

column in
a
> > grid,
> > > you need to ad a column to your datagrid and make it invisible
with
a
> > > stylesheet rule.
> > >
> > > Note, if you use a server control and set property Visible to

false, the
> > > control won't be rendered to the client and you won't get anything. > > >
> > > Eliyahu
> > >
> > > "Mike Fellows" <mi***************@equityhouse.co.uk> wrote in

message
> > > news:WpbEc.1276$Cs1.434@newsfe6-win...
> > > > Ok, im not sure if this is at all possible and if it is how i
go about
> > it
> > > is
> > > > beyond me
> > > >
> > > > i have a piece of client side code that requires a piece of data from
> > the
> > > > server side (an ID number in this case)
> > > >
> > > > how can i pass the data from one side to the other, or

retrieve it > from
> > > the
> > > > webform on the client side?
> > > >
> > > > i hope ive explained this properly
> > > >
> > > > Mike Fellows
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 18 '05 #8
you are a superstar

thanks Eliyahu

Mike
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Mike,

A few things:

You can't have webcontrols outside <form> tags.

The javascript should be a function and you should call it on client-side
load event:
<SCRIPT language="javascript">
var id;
function getId() {id=hiddenId.innerText;}
</SCRIPT>
...
<body MS_POSITIONING="GridLayout" onload="getId()">
After this variable id is available to other javascripts functions on the
page.

Also the stylesheet rule for Hidden is missing, unless you don't want to
hide the id.

Eliyahu

"Mike Fellows" <mi***************@equityhouse.co.uk> wrote in message
news:OyfEc.2307$Cs1.737@newsfe6-win...
Eliyahu,

ok all worked fine on the server side, but i get an error on page on load

im including my code so you can see what im doing, i think the problem lies
within the javascript script

thanks

Mike

<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">

<SCRIPT language="javascript">
var id=hiddenId.innerText
</SCRIPT>

<SCRIPT language="VBScript">
Dim objWord
Dim exists
Sub OpenDoc()
Set objWord = CreateObject("Word.Application")
objWord.Documents.Open("\\Gringotts\common
documents\AutoPackProduction\Remortgage\Factfind.d oc")
objWord.Visible = true
objWord.activedocument.saveas("c:\"& id &".doc")
set objWord=nothing
End Sub
</SCRIPT>

</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
</form>
<input style="Z-INDEX: 101; LEFT: 165px; WIDTH: 157px; POSITION:

absolute;
TOP: 82px; HEIGHT: 48px"
onclick="opendoc()" type="button" value="opendoc">&nbsp;
<asp:label id="hiddenId" style="Z-INDEX: 102; LEFT: 50px; POSITION:
absolute; TOP: 28px" runat="server"
CssClass="Hidden"></asp:label>
</body>
</HTML>

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:OG**************@tk2msftngp13.phx.gbl...
Mike,

Let's say you want to pass hidden id value from server to client.

1. Add a hidden label control to the aspx page:
<asp:Label id="hiddenId" runat="server" CssClass="Hidden"></asp:Label>
Add a stylesheet rule for Hidden to the page: .Hidden{display:none}

2. In the code-behind on server-side assign values to the id:
hiddenId.Text = "12345";

3. In javascripts on client-side get the value:
var id=hiddenId.innerText;

If it is not clear, please tell me what step causes a problem.

Eliyahu

"Mike Fellows" <mi***************@equityhouse.co.uk> wrote in message
news:yweEc.2058$Cs1.739@newsfe6-win...
> Eliyahu,
>
> I hate to be a pain, but im probably more confused than ever
>
> could you point me in the direction of an example at all?
> (ive tried searching for them but i cant find any)
>
> Thanks
>
> Mike
>
>
> "Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
> news:ei*************@tk2msftngp13.phx.gbl...
> > That's fine. Give you label an id and refer to it from javascript. If
it
> is
> > an asp:Label, it will translate to <span> and you can get the label text
> via
> > innerText property.
> >
> > Eliyahu
> >
> > "Mike Fellows" <mi***************@equityhouse.co.uk> wrote in

message > > news:s1eEc.1931$Cs1.1084@newsfe6-win...
> > > Eliyahu,
> > >
> > > ok i sort of understand (though not fully)
> > >
> > > if i have a label on my webform called MyLabel
> > >
> > > and i have a clientside HTML button that runs my client side
code > > >
> > > i want my HTML button to get the value of MyLabel so that i can us e
it
> > > clientside
> > >
> > >
> > >
> > >
> > >
> > > "Eliyahu Goldin" <re*************@monarchmed.com> wrote in
message > > > news:u2**************@TK2MSFTNGP10.phx.gbl...
> > > > Mike,
> > > >
> > > > This is one of the most common tasks in ASP.NET development. The > > solution
> > > is
> > > > to use hidden elements. If you need a single id value, you can

use any
> > > html
> > > > element capable of holding values. If you need to pass the value back,
> > you
> > > > need to use a <input type="hidden" ...>. If you need an id column
in
a
> > > grid,
> > > > you need to ad a column to your datagrid and make it invisible

with
a
> > > > stylesheet rule.
> > > >
> > > > Note, if you use a server control and set property Visible to

false,
> the
> > > > control won't be rendered to the client and you won't get

anything.
> > > >
> > > > Eliyahu
> > > >
> > > > "Mike Fellows" <mi***************@equityhouse.co.uk> wrote in
message
> > > > news:WpbEc.1276$Cs1.434@newsfe6-win...
> > > > > Ok, im not sure if this is at all possible and if it is how

i go > about
> > > it
> > > > is
> > > > > beyond me
> > > > >
> > > > > i have a piece of client side code that requires a piece of data > from
> > > the
> > > > > server side (an ID number in this case)
> > > > >
> > > > > how can i pass the data from one side to the other, or

retrieve
it
> > from
> > > > the
> > > > > webform on the client side?
> > > > >
> > > > > i hope ive explained this properly
> > > > >
> > > > > Mike Fellows
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 18 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by KKramsch | last post: by
10 posts views Thread by vbMark | last post: by
7 posts views Thread by Cemal Karademir | last post: by
1 post views Thread by Carlos Alejandro Pérez | last post: by
6 posts views Thread by Jerry Camel | last post: by
22 posts views Thread by Arne | last post: by
7 posts views Thread by =?iso-8859-1?Q?S=F8ren_M._Olesen?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.