tags:

views:

35

answers:

1

this.Page.ClientScript.RegisterClientScriptInclude("utility.popupUrl(CaptchaLogin.aspx)","");

+1  A: 

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

David Hedlund
Thanks, i tried with below syntax still i have errors this.Page.ClientScript.RegisterClientScriptBlock(typeof(string), "utility.popupUrl('CaptchaLogin.aspx')","<script language=javascript src='~/Public/JS/FailLogin.js'>",true);any suggestion
vasanth
see my edit. i hope that clears things up a bit.
David Hedlund
Thanks, i got the pop window, but i want diapaly that window centre of page page. please any reference reply to me
vasanth
that's got nothing to do with this at all. if the script block registering worked out for you, you should accept this question as the answer, and start a new question where you describe what you want to do. and when you do, you really need to provide some code. nobody can tell you what you're doing wrong, if you're not telling us what you're doing.
David Hedlund
Thanks For your Suggestion
vasanth