Client Side Values passed from Server

  • Thread starter Thread starter John Cosmas
  • Start date Start date
J

John Cosmas

In the old form of ASP when code was executed all on one single page, I was
able to set a value into a variable and use it all over the page like this -

<% pvntDate = Date() %>
<input type="button" ID="btnTest" onclick="window.open('test.asp?mydate=<% =
pvntDate %>')">

I would like to reproduce this from the server side in the new .NET
implementation so I could pass the date value into the client side of the
page as it appear in the example above. Please help...

TIA
John
 
if you are using webcontrols and button class or any thing like imagebutton
etc you should use
attributes collection and add custom values to it

in this case you want to add a clientside onclick attribute so you do
something like this

btnTest.Attributes.Add("onclick", "window.open('test.aspx?mydate" +
datetime.now + "')");

something as simple as that will add a client side attribute the the
webcontrol and will have the desired effect.

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
 
In the old form of ASP when code was executed all on one single page,
I was able to set a value into a variable and use it all over the page
like this -

<% pvntDate = Date() %>
<input type="button" ID="btnTest"
onclick="window.open('test.asp?mydate=<% = pvntDate %>')">

Just declare a page level variable:

Private MyVariable as datetime
 
You have to declare the variable as PUBLIC instead of PRIVATE, otherwise the
client cannot get to the server-side code.
 
You have to declare the variable as PUBLIC instead of PRIVATE,
otherwise the client cannot get to the server-side code.


Client side code cannot access server-side code...

The OP wanted to have a page level variable, so declaring it private would
be fine.
 
Back
Top