473,322 Members | 1,268 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Having problems with 'RegisterStartUpScript'.

When I put this code in my load function it works just fine.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
RegisterStartupScript("", "<script language='JavaScript'> CreateWnd
('PleaseWait.aspx', 500, 50, false); </script>")
End Sub
But when I put it in another server control it doesn't work:

Private Sub ImageList_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
ImageList.ItemCommand

RegisterStartupScript("", "<script language='JavaScript'> CreateWnd
('PleaseWait.aspx', 500, 50, false); </script>")

End Sub

Can someone tell me why this isn't working?
And here is the script code.
/*/
/ / Author: Jeremy Falcon
/ / Date: November 08, 2001
/ / Version: 1.4
/*/

/*/ THIS FILE CONTAINS FUNCTIONS THAT WILL WRAP THE POP-UP PROCESS /*/

// this variable will hold the window obect
// we only allow one pop-up at a time
var popup = null;

/*/
/ / PURPOSE:
/ / To create and center a pop-up window.
/ /
/ / COMMENTS:
/ / It will replace to old pop-up if called
/ / without calling DestroyWnd() first..
/*/

function CreateWnd (file, width, height, resize)
{
var doCenter = false;

if((popup == null) || popup.closed)
{
attribs = "";

/*/ there's no popup displayed /*/

// assemble some params
if(resize) size = "yes"; else size = "no";

/*/
/ / We want to center the pop-up; however, to do this we need to know
the
/ / screen size. The screen object is only available in JavaScript
1.2 and
/ / later (w/o Java and/or CGI helping), so we must check for the
existance
/ / of it in the window object to determine if we can get the screen
size.
/ /
/ / It is safe to assume the window object exists because it was
implemented
/ / in the very first version of JavaScript (that's 1.0).
/*/
for(var item in window)
{ if(item == "screen") { doCenter = true; break; } }

if(doCenter)
{ /*/ center the window /*/

// if the screen is smaller than the window, override the resize
setting
if(screen.width <= width || screen.height <= height) size = "yes";

WndTop = (screen.height - height) / 2;
WndLeft = (screen.width - width) / 2;

// collect the attributes
attribs = "width=" + width + ",height=" + height + ",resizable=" +
size + ",scrollbars=" + size + "," +
"status=no,toolbar=no,directories=no,menubar=no,lo cation=no,top=" +
WndTop + ",left=" + WndLeft;
}
else
{
/*/
/ / There is still one last thing we can do for JavaScrpt 1.1
/ / users in Netscape. Using the AWT in Java we can pull the
/ / information we need, provided it is enabled.
/*/
if(navigator.appName=="Netscape" && navigator.javaEnabled())
{ /*/ center the window /*/

var toolkit = java.awt.Toolkit.getDefaultToolkit();
var screen_size = toolkit.getScreenSize();

// if the screen is smaller than the window, override the resize
setting
if(screen_size.width <= width || screen_size.height <= height) size
= "yes";

WndTop = (screen_size.height - height) / 2;
WndLeft = (screen_size.width - width) / 2;

// collect the attributes
attribs = "width=" + width + ",height=" + height + ",resizable=" +
size + ",scrollbars=" + size + "," +
"status=no,toolbar=no,directories=no,menubar=no,lo cation=no,top=" +
WndTop + ",left=" + WndLeft;
}
else
{ /*/ use the default window position /*/

// override the resize setting
size = "yes";

// collect the attributes
attribs = "width=" + width + ",height=" + height + ",resizable=" +
size + ",scrollbars=" + size + "," +
"status=no,toolbar=no,directories=no,menubar=no,lo cation=no";
}
}

// create the window
popup = open(file, "", attribs);
}
else
{
// destory the current window
DestroyWnd();
// recurse, just once, to display the new window
CreateWnd(file, width, height, resize);
}
}

/*/
/ / PURPOSE:
/ / To destroy the pop-up window.
/ /
/ / COMMENTS:
/ / This is available if wish to destroy
/ / the pop-up window manually.
/*/
Nov 19 '05 #1
4 1850
"=?Utf-8?B?Sm9zZXBoIEJ1cnRvbg==?="
<Jo**********@discussions.microsoft.com> wrote in
news:45**********************************@microsof t.com:
When I put this code in my load function it works just fine.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
RegisterStartupScript("", "<script language='JavaScript'>
CreateWnd
('PleaseWait.aspx', 500, 50, false); </script>")
End Sub
But when I put it in another server control it doesn't work:

Private Sub ImageList_ItemCommand(ByVal source As Object, ByVal
e As System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
ImageList.ItemCommand

RegisterStartupScript("", "<script language='JavaScript'>
CreateWnd
('PleaseWait.aspx', 500, 50, false); </script>")

End Sub

Can someone tell me why this isn't working?


Joseph,

Why is the first parameter to RegisterStartupScript an empty string?

What do you mean by "this isn't working"? Do you get an error
message?

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 19 '05 #2
I put an empty string because I figured I didn't need to use a key value.

And I don't get an error message, its hits that part of the code and doesn't
do anything.

When I step through the code when its in the load function, I get my popup.
But when I do it anywhere else I don't get my popup.

"Chris R. Timmons" wrote:
"=?Utf-8?B?Sm9zZXBoIEJ1cnRvbg==?="
<Jo**********@discussions.microsoft.com> wrote in
news:45**********************************@microsof t.com:
When I put this code in my load function it works just fine.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
RegisterStartupScript("", "<script language='JavaScript'>
CreateWnd
('PleaseWait.aspx', 500, 50, false); </script>")
End Sub
But when I put it in another server control it doesn't work:

Private Sub ImageList_ItemCommand(ByVal source As Object, ByVal
e As System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
ImageList.ItemCommand

RegisterStartupScript("", "<script language='JavaScript'>
CreateWnd
('PleaseWait.aspx', 500, 50, false); </script>")

End Sub

Can someone tell me why this isn't working?


Joseph,

Why is the first parameter to RegisterStartupScript an empty string?

What do you mean by "this isn't working"? Do you get an error
message?

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

Nov 19 '05 #3
Hi:

I believe you must complete the first parameter because it's an
identification.
--
Thales - Services Division
Bulnes 2756 P.5 - C1425DKX
Ciudad Autónoma de Buenos Aires
Tel.: (+5411) 4806-9146
Fax.: (+5411) 4807-0563
"Joseph Burton" wrote:
When I put this code in my load function it works just fine.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
RegisterStartupScript("", "<script language='JavaScript'> CreateWnd
('PleaseWait.aspx', 500, 50, false); </script>")
End Sub
But when I put it in another server control it doesn't work:

Private Sub ImageList_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
ImageList.ItemCommand

RegisterStartupScript("", "<script language='JavaScript'> CreateWnd
('PleaseWait.aspx', 500, 50, false); </script>")

End Sub

Can someone tell me why this isn't working?
And here is the script code.
/*/
/ / Author: Jeremy Falcon
/ / Date: November 08, 2001
/ / Version: 1.4
/*/

/*/ THIS FILE CONTAINS FUNCTIONS THAT WILL WRAP THE POP-UP PROCESS /*/

// this variable will hold the window obect
// we only allow one pop-up at a time
var popup = null;

/*/
/ / PURPOSE:
/ / To create and center a pop-up window.
/ /
/ / COMMENTS:
/ / It will replace to old pop-up if called
/ / without calling DestroyWnd() first..
/*/

function CreateWnd (file, width, height, resize)
{
var doCenter = false;

if((popup == null) || popup.closed)
{
attribs = "";

/*/ there's no popup displayed /*/

// assemble some params
if(resize) size = "yes"; else size = "no";

/*/
/ / We want to center the pop-up; however, to do this we need to know
the
/ / screen size. The screen object is only available in JavaScript
1.2 and
/ / later (w/o Java and/or CGI helping), so we must check for the
existance
/ / of it in the window object to determine if we can get the screen
size.
/ /
/ / It is safe to assume the window object exists because it was
implemented
/ / in the very first version of JavaScript (that's 1.0).
/*/
for(var item in window)
{ if(item == "screen") { doCenter = true; break; } }

if(doCenter)
{ /*/ center the window /*/

// if the screen is smaller than the window, override the resize
setting
if(screen.width <= width || screen.height <= height) size = "yes";

WndTop = (screen.height - height) / 2;
WndLeft = (screen.width - width) / 2;

// collect the attributes
attribs = "width=" + width + ",height=" + height + ",resizable=" +
size + ",scrollbars=" + size + "," +
"status=no,toolbar=no,directories=no,menubar=no,lo cation=no,top=" +
WndTop + ",left=" + WndLeft;
}
else
{
/*/
/ / There is still one last thing we can do for JavaScrpt 1.1
/ / users in Netscape. Using the AWT in Java we can pull the
/ / information we need, provided it is enabled.
/*/
if(navigator.appName=="Netscape" && navigator.javaEnabled())
{ /*/ center the window /*/

var toolkit = java.awt.Toolkit.getDefaultToolkit();
var screen_size = toolkit.getScreenSize();

// if the screen is smaller than the window, override the resize
setting
if(screen_size.width <= width || screen_size.height <= height) size
= "yes";

WndTop = (screen_size.height - height) / 2;
WndLeft = (screen_size.width - width) / 2;

// collect the attributes
attribs = "width=" + width + ",height=" + height + ",resizable=" +
size + ",scrollbars=" + size + "," +
"status=no,toolbar=no,directories=no,menubar=no,lo cation=no,top=" +
WndTop + ",left=" + WndLeft;
}
else
{ /*/ use the default window position /*/

// override the resize setting
size = "yes";

// collect the attributes
attribs = "width=" + width + ",height=" + height + ",resizable=" +
size + ",scrollbars=" + size + "," +
"status=no,toolbar=no,directories=no,menubar=no,lo cation=no";
}
}

// create the window
popup = open(file, "", attribs);
}
else
{
// destory the current window
DestroyWnd();
// recurse, just once, to display the new window
CreateWnd(file, width, height, resize);
}
}

/*/
/ / PURPOSE:
/ / To destroy the pop-up window.
/ /
/ / COMMENTS:
/ / This is available if wish to destroy
/ / the pop-up window manually.
/*/

Nov 19 '05 #4
>> > Private Sub ImageList_ItemCommand(ByVal source As Object,
> ByVal e As
> System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
> ImageList.ItemCommand
>
> RegisterStartupScript("", "<script
> language='JavaScript'> CreateWnd
> ('PleaseWait.aspx', 500, 50, false); </script>")
>
> End Sub

Joseph,

When the user clicks on an item, are you expecting the above code to
cause the window to popup? If so, please realize that server-side
code cannot directly cause client-side JavaScript to execute. You
will have to inject calls to the JavaScript in the ASP.Net controls
when the page is built (this is usually done in Page_Load).

Unfortunately, there seems to be a lack of resources on the web as to
how to integrate client-side JavaScript code and server-side
ASP.Net code. It's quite elegant when you know how, but getting that
knowledge can be a real challenge.

Right now I'm pretty much guessing as to what you want your code to
do. So, if you'd like, please post a step-by-step description of
what you want to happen, something like:

- page with datagrid is displayed on the client
- user clicks an item in the datagrid
- client-side code shows a window in response to the click
- postback occurs

We can use an algorithm like this as a starting point to getting the
JavaScript calls wired into the correct places at the correct point
in the page's lifecycle.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lukman | last post by:
Hi, Could you tell me about what is RegisterStartupScript, I try to understand from MSDN sample, but I still don't understand. Could you give me more simple sample ? and what is the purpose of...
6
by: Bill Jones | last post by:
I'm trying to use this.RegisterStartupScript to add some javascript to and aspx page that will run when the page is loaded. Does anyone know if this function only works in the Page_Load function? ...
11
by: Stan Sainte-Rose | last post by:
Hi, I m working on a user control. I need to use a Js file, I would like to know how to load the js file using RegisterStartupScript command from the user control. Also, if I load the same user...
3
by: Mike | last post by:
Hi, I am trying to resize a HTML table through Javascript. When the user control loads the first time, the table is resized, but then it doesn't anymore. I am using the following code in the...
2
by: Marshal Antony | last post by:
Hi, I have a problem with using Page.RegisterStartupScript to call some javascript code from ASP.NET using C# is not working in Netscape.It is working fine in Internet Explorer.Does anybody know...
0
by: rom | last post by:
my main aspx page has 3 user controls. they are all located in the same place of the page and each time i set the visibility of 2 of them to false and 1 to true. now, i want to use the...
3
by: MJP | last post by:
I have a button which kicks off the generation of a report after which the file will be downloaded. The report generation can take a long time, so client side onclick event of the button also...
3
by: Rob | last post by:
Hi, We've developed an ajax enabled web app which we're currently deploying to our production server. We use System.Web.UI.Page.RegisterStartupScript throughout the app, and all has worked well...
4
by: =?Utf-8?B?RHVuZTg4?= | last post by:
I've got some code that uses Page.ClientScript.RegisterStartupScript to call a javascript function from the Page_Load method in the code behind. The code works fine in IE but the javascript...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.