/    Sign up×
Community /Pin to ProfileBookmark

Server-events to javascript

Hi all,

I have the following problem:

Depending on an event within de asp.net-page I like to start a Javascript in the HTML.

Example: On a webform I have an asp-dropdownlist. When the user clicks on an item of it, the program has to show (were hidden) some textboxes, depending of the choice he made in de dropdownlist.
These textboxes are HTML-controls (not asp-controls) and are not “known” within the codebehind, so I cannot “reach” them.
Now I want the javascript to make these textboxes “visible” and do some action on it.
How do I solve this ???

Help is appreciated,

regards, Ger.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@agent_bozoSep 30.2005 — asp's not really my area of expertise, but when I create custom forms / navbars with dropdown feature, I tend to use css and lists (see http://www.alistapart.com/articles/dropdowns).

I may be barking up the wrong tree, but by doing it this way you might then be able to create asp-controls for each list item.
Copy linkTweet thisAlerts:
@CharlesSep 30.2005 — Looks like you need a FRAME of an IFRAME.
Copy linkTweet thisAlerts:
@GerEieltsauthorSep 30.2005 — Thanks guys for answering,

In fact, I can reduce the question to: is it possible to "call" a javascript from the codebehind.

So: user clicks on dropdownlist, AutoPostback is true, so the server runs the codebehind, server returns the page to the clients browser and than invokes the javascript.

Charles, I donot understand what FRAME has got to do with this. Can you explain ?

Ger.
Copy linkTweet thisAlerts:
@CharlesSep 30.2005 — JavaScript cannot communicate with the outside world. There is a way that you can trick it into sending an HTTP request but it can't get the reponse. That's JavaScript. A few browsers have extended JavaScript so that it can receive responses but each browser does that differently. Best tostay away from browser specific pages.

Put the text boxes in an IFRAME and then use the "target" attribute to get the FORM's response posted there. See http://www.w3.org/TR/html401/interact/forms.html#h-17.3 and http://www.w3.org/TR/html401/present/frames.html#edef-IFRAME .
Copy linkTweet thisAlerts:
@ScriptageSep 30.2005 — You can do it using AJAX.

A simpler way perhaps is to make the server write out a javascript file with variables in that can be read and manipulated.

Using this code the asp page needs to write out a variable:

loaded = true;

You can then add anything you like

var page = 1;

<script>

var loaded = false;

var timeout = 10;

var t = 0;

function invoke_server_response(value){

var response = document.createElement("script");

response.id = "server_response";

response.src = "sresponse.asp?value=" + escape(value);

document.getElementByTagName("head")[0].appendChild(response);

await_response();

}

function await_response(){

t++;

if(t == timeout * 2){

alert("Connection timed out");

return false;

}else if(!loaded){

window.setTimeout("await_response()", 0500);

}else{

// The server has responded.

if(page == 1){

document.write("This is page 1");

}else if(page == 2){

document.write("This is page 2");

}else{

document.write("The Page you are looking for cannot be found");

}

}

}

</script>

Regards
Copy linkTweet thisAlerts:
@GerEieltsauthorOct 01.2005 — Thanks for replying Scriptage....

I tried your proposal, but it is too difficult for me to understand....

Will search further... Ger.
×

Success!

Help @GerEielts spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...