Having problems with 'RegisterStartUpScript'.

G

Guest

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,location=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,location=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,location=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.
/*/
 
C

Chris R. Timmons

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?
 
G

Guest

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.
 
G

Guest

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
 
C

Chris R. Timmons

Private Sub ImageList_ItemCommand(ByVal source As Object,

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top