 |
| ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

April 21st, 2006, 12:22 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
How 2 Add Dynamic JScript to a WebForm
I would like to add something like the following to a page to have the ability to post an alert on the user's screen.
Code:
<script>
var msg = ""; // <ââ<<< I want to be able to modify what's between
// the quotes when sending the page.
function PostMessage()
{
if (msg != "")
{
alert(msg);
msg = "";
}
}
</script>
</head>
<body onload="return PostMessage();">
. . .
Not sure how to modify the contents of msg at the server...
Seems to me there's a problem also with including script like that. (Maybe what I'm recalling is the difficulty adding things like onkeypress to asp: controls. Whatever I'm remembering involved adding properties to the controls at runtime...)
|
|

April 23rd, 2006, 01:24 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Look into Page.RegisterStartupScript and Page.RegisterClientScriptBlock methods in the VS Help.
|
|

June 5th, 2006, 02:33 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
I don't want to register a block, I just want to fill in a small group of characters at that specific location in the rendered stuff going to the client. Is there some way of doing that (ala WebClass replaceable tags)?
|
|

June 5th, 2006, 03:57 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Brian,
You can use old skool ASP delimiters and call a method in the Code Behind like this:
var msg = '<%= YourServerSideMethod() %>';
where YourServerSideMethod is a method that returns a string.
Alternatively, you could add the text to, say, a server side div and then use document.GetElementById to get the text and alert it.
That said, the RegisterClientScriptBlock suggested by jbenson001 makes a lot of sense. The entire PostMessage could be registered in the block, including the variable text. The benefit of that is that you only need to send the block when there is a message. That way, you don't need to check for "if (msg != "")" and better yet, you eliminate the need to send the block at all when there's no message.
HtH,
Imar
|
|

June 6th, 2006, 02:53 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
Thatâs pretty good reasoning...
(I just hate to do it that way though, because then the main functionality is not there, lying on the surface. Rather you have to go track down what is going to happen when the machine encounters that instruction to add the script block.)
Thanks.
|
|

June 6th, 2006, 03:30 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yeah, I agree. It makes it harder indeed to see what's going on where.
That's what I like so much about .NET: there are so many ways to do the same thing, there's always a way to do it that suits you best... ;)
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: Beating of my heart / Moa X by Various Artists (Track 13 from the album: Ibiza Lounge) What's This?
|
|
 |