this.Page.ClientScript.RegisterClientScriptInclude("utility.popupUrl(CaptchaLogin.aspx)","");
views:
35answers:
1I got error while calling as popup window for .aspx page, is it right syntax? please reply to ame
Nope, that's not right. When you register a client script include you're supposed to supply a url to a javascript file that contains the code you want to execute. That will render as <script type="text/javascript" src="your url..."></script>
What you want to do is RegisterScript
Block
. In that method, you also need to make sure you're passing the generateScriptTags
flag (or what it's called) as true
.
EDIT
With regards to your comment, I don't know exactly what you wanted the script to do, but it looks like you tried to register a script block and a script include, which a) won't go, and b) wasn't part of your original question. I'll try to reply step by step on things you need to change:
The first parameter, type
, should generally be a reference to a page type. If you're in a user control, you can achieve this by this.Page.GetType()
, if you're in a page, this.GetType()
will suffice. Regardless of where you are, you could do typeof(System.Web.UI.Page)
The second parameter is not supposed to contain any actual script; it is just a key to identify the script. You want to be able to identify the script, so that you can, say, check if it is registered, as in the example below. You can choose pretty much whatever to be your key, just as you choose, say, variable names.
The third parameter is your actual script. If you pass the fourth parameter as true
, it can just be a piece of javascript. If the value of the fourth parameter is false
you will need to manuallly include the <script>
tags in your third parameter.
if(!ClientScript.IsClientScriptBlockRegistered("CaptchaLogin"))
ClientScript.RegisterClientScriptBlock(typeof(Page), "CaptchaLogin", "utility.popupUrl('CaptchaLogin.aspx');", true);
Now, to include the script file FailLogin.js
, you cannot use RegisterClientScriptBlock
at all. You will need to use RegisterClientScriptInclude
as in your original post. Here, the first parameter is also just a key. No script goes in there at all. The second parameter is the URL to the file you want to include:
ClientScript.RegisterClientScriptInclude("CaptchaInclude", "/Public/JS/FailLogin.js");
I should add that I'm not sure whether you can use the tilde, ~
, to quantify your url in RegisterClientScriptInclude
, perhaps you can. I am sure, however, that you can definitely not use it in a string the way you did in the code you posted in the comment to this answer.