|
-
Jun 22nd, 2006, 06:15 AM
#1
Thread Starter
Frenzied Member
clientscript.RegisterStartupScript
In asp.net 1.1 I had no problems using this:
Page.RegisterStartupScript("ClientScript", strScript)
But as I moved to asp.net 2.0 I receive an error, it recommends me to use
ClientScript.RegisterStartupScript instead. Which arguments do I need to execute the same as in 1.1?
-
Jun 22nd, 2006, 08:24 AM
#2
Frenzied Member
Re: clientscript.RegisterStartupScript
Did not get to .net 2 yet, but try Response.Write(myscript)
-
Jun 22nd, 2006, 08:30 AM
#3
Re: clientscript.RegisterStartupScript
Although I see no documentation on it, I'd assume it's the same as Page.RegisterStartupScript().
Response.Write isn't a good idea in most cases...
-
Jun 22nd, 2006, 08:32 AM
#4
Frenzied Member
Re: clientscript.RegisterStartupScript
 Originally Posted by mendhak
Although I see no documentation on it, I'd assume it's the same as Page.RegisterStartupScript().
Response.Write isn't a good idea in most cases...
I can swear it was you that recommended that to me....*scratching head*
-
Jun 22nd, 2006, 08:32 AM
#5
Re: clientscript.RegisterStartupScript
You need to use ClientScriptManager.RegisterStartupScript, Page.RegisterStartupScript has been removed from .NET 2.0.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Jun 22nd, 2006, 10:26 AM
#6
Thread Starter
Frenzied Member
Re: clientscript.RegisterStartupScript
ok, but I can't type ClientScriptManager.RegisterStartupScript("ClientScript", strScript), what kind of arguments does this require?
-
Jun 23rd, 2006, 02:19 AM
#7
Re: clientscript.RegisterStartupScript
You don't have to use ClientScriptManager, that was a Typo 
Anyways here is an example
VB Code:
ClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('hello')", True)
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Jun 23rd, 2006, 02:23 AM
#8
Thread Starter
Frenzied Member
Re: clientscript.RegisterStartupScript
Great, I will try that, thanks
-
Jun 24th, 2006, 11:32 AM
#9
Re: clientscript.RegisterStartupScript
 Originally Posted by StrangerInBeijing
I can swear it was you that recommended that to me....*scratching head*
I was the one who was totally against it. I must've given so many lectures on it that subject that you associated it with me.
-
Jun 29th, 2006, 02:50 AM
#10
Thread Starter
Frenzied Member
Re: clientscript.RegisterStartupScript
Now I've tried the code
ClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('hello')", True)
but now it says
Code:
Error 442 Name 'ClientScript' is not declared. e:\Visual Studio 2005\WebSites\GF\Pressure1Abs.ascx.vb 383 9 e:\...\GF\
-
Jun 29th, 2006, 05:32 AM
#11
Re: clientscript.RegisterStartupScript
Use
Code:
Page.ClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('hello')", True)
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Jun 29th, 2006, 07:22 AM
#12
Thread Starter
Frenzied Member
Re: clientscript.RegisterStartupScript
It doesn't work, nothing happens when I execute that code??? Does it work for you? I am using a beta of IE7, could it be that?
-
Jun 29th, 2006, 07:27 AM
#13
Thread Starter
Frenzied Member
Re: clientscript.RegisterStartupScript
It doesn't work, because a ";" is missing after the JS-code. Now it works ;-). Thanks
-
Jul 19th, 2008, 01:28 PM
#14
New Member
Re: clientscript.RegisterStartupScript
Thank men
ClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('hello')", True)
Work...
yea
-
Jul 19th, 2008, 04:59 PM
#15
Lively Member
Re: clientscript.RegisterStartupScript
vb Code:
ScriptManager.RegisterStartupScript(Me, Page.GetType, "scriptkey", "yourScript();", True)
Use it all the time, just make sure you have a script manager on the page above it.
Visual Studio 2005 - Visual Basic and C#
Love that SQL
-
Jul 8th, 2010, 11:34 AM
#16
New Member
Re: clientscript.RegisterStartupScript
Hi -- My question is related to this thread. I'm using clientscript.RegisterStartupScript in a child page to register a script and have it execute after the page loads. The code is as follows
ClientScript.RegisterStartupScript(GetType(Page), "", "OnInitial();", True)
THe script OnInitial() is contained in an external file and it looks like this:
var nSubtopics;
var nTopics;
var aTopicText;
var aTopicValue;
var aSubtopicText;
var aSubtopicValue;
var nSelectedTopic;
var nSelectedSubtopic;
function OnInitial()
{
//debugger;;
var i, j, n, strTopic, strSubtopic;
nTopics =document.getElementById("_ctl0_ContentPlaceHolder1_ddlTopic").options.length;
aTopicText = new Array(nTopics);
aTopicValue = new Array(nTopics);
for (i=0; i< nTopics; i++)
{
aTopicText[i] = document.getElementById("_ctl0_ContentPlaceHolder1_ddlTopic").options[i].text;
aTopicValue[i] = document.getElementById("_ctl0_ContentPlaceHolder1_ddlTopic").options[i].value;
}
nSubtopics = document.getElementById("_ctl0_ContentPlaceHolder1_ddlSubtopic").options.length;
aSubtopicText = new Array(nSubtopics);
aSubtopicValue = new Array(nSubtopics);
for (i = 0; i < nSubtopics; i++) {
aSubtopicText[i] = document.getElementById("_ctl0_ContentPlaceHolder1_ddlSubtopic").options[i].text;
aSubtopicValue[i] = document.getElementById("_ctl0_ContentPlaceHolder1_ddlSubtopic").options[i].value;
}
nSelectedTopic = document.getElementById("_ctl0_ContentPlaceHolder1_ddlTopic").selectedIndex;
nSelectedSubtopic = document.getElementById("_ctl0_ContentPlaceHolder1_ddlSubtopic").selectedIndex;
if (nSelectedTopic == 0) {
document.getElementById("_ctl0_ContentPlaceHolder1_ddlSubtopic").options.length = 1;
}
else {
strTopic = document.getElementById("_ctl0_ContentPlaceHolder1_ddlTopic").options[nSelectedTopic].text;
n = strTopic.length;
j = 0;
for (i = 1; i < nSubtopics; i++) {
strSubtopic = aSubtopicValue[i];
if (strTopic != strSubtopic.substring(0, n))
{
document.getElementById("_ctl0_ContentPlaceHolder1_ddlSubtopic").options[i - j] = null;
j++;
}
}
}
}
function OnChangeTopic()
{ var i, j, n, strTopic, strSubtopic,strSubtopicVal;
if (nSelectedTopic != document.getElementById("_ctl0_ContentPlaceHolder1_ddlTopic").selectedIndex)
{
nSelectedTopic = document.getElementById("_ctl0_ContentPlaceHolder1_ddlTopic").selectedIndex;
strTopic = document.getElementById("_ctl0_ContentPlaceHolder1_ddlTopic")[nSelectedTopic].text;
document.getElementById("_ctl0_ContentPlaceHolder1_ddlSubtopic").options.length = 1;
if (nSelectedTopic != 0)
{
j = 1;
n = strTopic.length;
for (i = 1; i < nSubtopics; i++)
{
//strSubtopic = aSubtopicValue[i];
strSubtopic = aSubtopicText[i];
strSubtopicVal = aSubtopicValue[i];
if (strTopic == strSubtopic.substring(0, n))
{
document.getElementById("_ctl0_ContentPlaceHolder1_ddlSubtopic").options[j] = new Option(strSubtopic.substring(n + 1, strSubtopic.length), strSubtopicVal);
if (nSelectedSubtopic == i) {
document.getElementById("_ctl0_ContentPlaceHolder1_ddlSubtopic").selectedIndex = j;
}
j++;
}
}
}
}
}
function OnChangeSubtopic()
{ var i, n, strSubtopic;
n = document.getElementById("_ctl0_ContentPlaceHolder1_ddlSubtopic").selectedIndex;
if (n == 0)
{
nSelectedSubtopic = 0;
}
else
{
strSubtopic = document.getElementById("_ctl0_ContentPlaceHolder1_ddlSubtopic")[n].value;
for (i = 1; i < nSubtopics; i++)
{
if (strSubtopic == aSubtopicValue[i])
{
nSelectedSubtopic = i;
break;
}
}
}
}
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
In IE7 this works OK. In IE8/FIreFox it does not work. It t cannot find the script. I get an "Object Expected" error.
Any help would be appriciated.
-
Jul 8th, 2010, 03:22 PM
#17
Re: clientscript.RegisterStartupScript
Hello jliotine,
Welcome to the forums!!
A couple of points I think that need to be made.
First of all, when posting into the forum, can you remember to surround your code in [CODE][/CODE] tags, it makes it so much easier to read.
Secondly, reviving a thread that is almost two years old doesn't really make much sense, it might have been better to start your own thread.
So to save me digging through the JavaScript, can you give a brief description of what your function does? Do you know at which point the JavaScript is failing? Have you tried debugging your JavaScript to try and isolate where the problem is?
Gary
-
Jul 9th, 2010, 02:05 AM
#18
Lively Member
Re: clientscript.RegisterStartupScript
how does this thread have 22,000 views??
-
Jul 9th, 2010, 06:17 AM
#19
Re: clientscript.RegisterStartupScript
 Originally Posted by jtm235
how does this thread have 22,000 views??
Because it was started in 2006
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|