By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,451 Members | 981 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,451 IT Pros & Developers. It's quick & easy.

Moving a string from client to server (JS -> ASPX)

P: n/a
In the client.js file i declare the
following variable.

...
var str = "info";
...

In the corresponding ASP file called
server.aspx.cs i declare two following
methods.

...
protected void Page_Load (
object sender, EventArgs e){...}
public void SomeThing () {
...
String data;
...}
...

The objective is to _SOMEHOW_ ensure
that the value of data (in the CS file)
is obtained from str (in the JS file).

Note that i don't need data to be
dynamically updated as soon as str is
changed. It's sufficient to call the
method SomeThing each time we pass the
part of code where we assign the value
"info" to str.

Note also that i need to notify
SomeThing about the value of str.

Of course, the actual situation is far
more complicated but my problem can be
boiled down to this simple case.

How should SomeThing be designed? How
need i to reconstruct the lines after
the assignment to str?

--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy

Jun 27 '08 #1
Share this Question
Share on Google+
11 Replies


P: n/a
K Viltersten wrote:
In the client.js file i declare the
following variable.

...
var str = "info";
...

In the corresponding ASP file called
server.aspx.cs i declare two following
methods.

...
protected void Page_Load (
object sender, EventArgs e){...}
public void SomeThing () {
...
String data;
...}
...

The objective is to _SOMEHOW_ ensure
that the value of data (in the CS file)
is obtained from str (in the JS file).

Note that i don't need data to be
dynamically updated as soon as str is
changed. It's sufficient to call the
method SomeThing each time we pass the
part of code where we assign the value
"info" to str.

Note also that i need to notify
SomeThing about the value of str.
It cannot be done without another HTTP request (can be XHR) because the two
don't know about each other. If you don't know that by now, you should get
some basic knowledge about client-server architectures first, before messing
around with them.

Your posting was not easily legible. The pronoun `I' is spelled with a
capital letter always and your line length is about half of what is expected
in Usenet (80 characters per line is the recommended maximum, 72 to 78 to
allow for quotation without reformat). Also, cross-posting over top-level
hierarchies is unwise as a news server may have comp.* within the Big 8
(Usenet) but not microsoft.* which does not belong to that. So the
discussion is going to be fragmented, and the conventions of communication
in the TLHs may also differ.

See also http://jibbering.com/faq/
Followup trimmed to c.l.js

PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Jun 27 '08 #2

P: n/a
>In the client.js file i declare the
>following variable.

...
var str = "info";
...

In the corresponding ASP file called
server.aspx.cs i declare two following
methods.

...
protected void Page_Load (
object sender, EventArgs e){...}
public void SomeThing () {
...
String data;
...}
...

The objective is to _SOMEHOW_ ensure
that the value of data (in the CS file)
is obtained from str (in the JS file).
It cannot be done without another HTTP request (can be XHR) because the
two
don't know about each other. If you don't know that by now, you should
get
some basic knowledge about client-server architectures first, before
messing
around with them.

Thanks! Trying not to be impolite i still need to point that the question
was "how can it be done", not the opposite. Are you suggesting that
the only (recommended) way to to request (another) page from the
server? It would be doable in my case, of course, but i'd prefer not to
send in the string using http://.../file.aspx?str=info.

Perhaps i could bake it in the sender object. What do you think?

--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy

Jun 27 '08 #3

P: n/a
VK
On May 18, 3:42 pm, "K Viltersten" <t...@viltersten.comwrote:
Are you suggesting that
the only (recommended) way to to request (another) page from the
server?
Welcome to HTTP ;-) It is a stateless protocol, so after the page is
served to the client, there is _no_ connection of any kind between the
page and the server: none.
The only way of communication HTTP has after that is a new request
initiated by the client: the server has no way to initiate anything.
It would be doable in my case, of course, but i'd prefer not to
send in the string using http://.../file.aspx?str=info.
You don't have to do that. Use AJAX or ol'good hidden iframe to
connect to the server and to report new src values.
Jun 27 '08 #4

P: n/a
K Viltersten wrote:
>>In the client.js file i declare the following variable.

...
var str = "info";
...

In the corresponding ASP file called server.aspx.cs i declare two
following methods.

protected void Page_Load (
object sender, EventArgs e){...}
public void SomeThing () {
...
String data;
...}
...

The objective is to _SOMEHOW_ ensure that the value of data (in the
CS file) is obtained from str (in the JS file).

It cannot be done without another HTTP request (can be XHR) because the
two don't know about each other. If you don't know that by now, you
should get some basic knowledge about client-server architectures
first, before messing around with them.

Thanks! Trying not to be impolite i still need to point that the question
was "how can it be done", not the opposite.
"It cannot be done without ... (can be ...) ..." reads pretty much the same
to me.
Are you suggesting that the only (recommended) way to to request
(another) page from the server?
Yes, the only way is to make a request to the server.
It would be doable in my case, of course,
but i'd prefer not to send in the string using
http://.../file.aspx?str=info.
You can also make a POST request, of course.
Perhaps i could bake it in the sender object. What do you think?
I don't know about a `sender' object. Must be ASP .NET-specific.

As I said, if you don't want to submit a form, you can do an XHR, something
along this:

var req = new XMLHttpRequest();
if (req)
{
req.open("POST", "file.aspx", true);

req.onreadystatechange = function() {
if (req.readyState == 4)
{
if (req.status == 200)
{
// handle success
}
else
{
// handle error
}
}
};

req.send("str=" + encodeURIComponent(str));
}

(See previous/other discussions about AJAX/XHR for details.)
Probably the `sender' object you are talking about is just a
Microsoft-provided wrapper for this.

Nothing will work without the sufficient support for client-side scripting
and XHR, but I guess as you are using ASP .NET which does not degrade
gracefully by default, you already know that.
PointedEars

P.S.
Signatures are to be delimited with "-- <CR><LF>", not "--<CR><LF>".
If you had that and your software messed with it, I suggest you fix it
or use better software. See also http://insideoe.com/
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Jun 27 '08 #5

P: n/a
>Are you suggesting that
>the only (recommended) way to to request (another)
page from the server?

Welcome to HTTP ;-) It is a stateless protocol, so
after the page is served to the client, there is
_no_ connection of any kind between the page and
the server: none.
The only way of communication HTTP has after that is
a new request initiated by the client: the server
has no way to initiate anything.
Got it. Thanks!
>It would be doable in my case, of course, but i'd
prefer not to send in the string using
http://.../file.aspx?str=info.

You don't have to do that. Use AJAX or ol'good
hidden iframe to connect to the server and to report
new src values.
Right. Got it. Thanks!

--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy

Jun 27 '08 #6

P: n/a
>>> ...
>>> var str = "info";
...

In the corresponding ASP file called server.aspx.cs i declare two
following methods.

protected void Page_Load (
object sender, EventArgs e){...}
public void SomeThing () {
...
String data;
...}
...

The objective is to _SOMEHOW_ ensure that the value of data (in the
CS file) is obtained from str (in the JS file).
>Are you suggesting that the only (recommended) way to to request
(another) page from the server?

Yes, the only way is to make a request to the server.
>It would be doable in my case, of course,
but i'd prefer not to send in the string using
http://.../file.aspx?str=info.

You can also make a POST request, of course.
>Perhaps i could bake it in the sender object. What do you think?

I don't know about a `sender' object. Must be ASP .NET-specific.

As I said, if you don't want to submit a form, you can do an XHR,
something along this:

var req = new XMLHttpRequest();
if (req)
{
req.open("POST", "file.aspx", true);

req.onreadystatechange = function() {
if (req.readyState == 4)
{
if (req.status == 200)
{
// handle success
}
else
{
// handle error
}
}
};

req.send("str=" + encodeURIComponent(str));
}

(See previous/other discussions about AJAX/XHR for details.)
Probably the `sender' object you are talking about is just a
Microsoft-provided wrapper for this.

Nothing will work without the sufficient support for client-side scripting
and XHR, but I guess as you are using ASP .NET which does not degrade
gracefully by default, you already know that.
Thanks.
See also http://insideoe.com/
Why should i go and visit a site for Outlook Express? Are you
recommending it? Sadly, i don't even think it's available on my
OS, so i guess i'll have to live without it.

--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy

Jun 27 '08 #7

P: n/a
K Viltersten meinte:
Why should i go and visit a site for Outlook Express? Are you
recommending it? Sadly, i don't even think it's available on my
OS, so i guess i'll have to live without it.

--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy
Whatever. You could still delimit your signature properly.

Gregor

--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Jun 27 '08 #8

P: n/a
K Viltersten wrote:
>See also http://insideoe.com/
Please include an attribution line, see http://jibbering.com/faq/#FAQ2_3
Why should i go and visit a site for Outlook Express? Are you
recommending it?
Quite the contrary. I can recommend Mozilla Thunderbird or KNode.
Sadly, i don't even think it's available on my
OS, so i guess i'll have to live without it.
As described on the site I pointed you to, Windows Mail that you are
apparently using is only the next version of Outlook Express for Windows
Vista, and apparently exhibits the same flaws.

http://insideoe.com/#the_future_of_Outlook_Express
F'up2 poster (hopefully they have fixed that bug by now)

PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Jun 27 '08 #9

P: n/a
>>See also http://insideoe.com/
>
Please include an attribution line, see http://jibbering.com/faq/#FAQ2_3
>Why should i go and visit a site for Outlook Express? Are you
recommending it?

Quite the contrary. I can recommend Mozilla Thunderbird or KNode.
ThunderBird has some fundamental flaws, as i've tried it but the
other one might be fun to test, perhaps. Thanks!
>Sadly, i don't even think it's available on my
OS, so i guess i'll have to live without it.

As described on the site I pointed you to, Windows Mail that you are
apparently using is only the next version of Outlook Express for
Windows Vista, and apparently exhibits the same flaws.

http://insideoe.com/#the_future_of_Outlook_Express
Oh, new name, old issues... Yhanks for the pointers. Let's see if
the signature works better now.

--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy

Jun 27 '08 #10

P: n/a
K Viltersten meinte:
ThunderBird has some fundamental flaws,
When compared to Windows Mail? I'm intrigued...
Let's see if the signature works better now.
It does.

Gregor

--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Jun 27 '08 #11

P: n/a
>ThunderBird has some fundamental flaws,
>
When compared to Windows Mail? I'm intrigued...
I've seen far too many casaulties of flame wars started by
this preludium. Since none of us two wish to be a troll, i
suggest we deem that as a matter of personal taste and
not go there. I believe every sane soul will agree... :)
>Let's see if the signature works better now.

It does.
I'm glad to hear that.

--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy

Jun 27 '08 #12

This discussion thread is closed

Replies have been disabled for this discussion.