javascript file call in Visual C# asp.net code

About programming a javascript file call in Load event of a control

Page 1 of 1

12 Replies - 10052 Views - Last Post: 23 June 2010 - 08:24 PM Rate Topic: -----

#1 supertime2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-February 10

javascript file call in Visual C# asp.net code

Posted 21 June 2010 - 03:41 AM

Calling a javascript file involves first registering it in Page.RegisterClientScriptBlock() in the Page_Load event and then call its function in a control e.g.

Page.RegisterClientScriptBlock("MyScript", _
"<script language=javascript src='MyJavascriptFile.js'>")


But how do you go about calling the following javascript file call in a Visual C# asp.net code?:

<script type="text/javascript" src="http://www.benchmarkemail.com/code/lbform.js?mFcQnoBFKMSnJvV2CKpXy%252BoNbCMyivkXsgDgIhejGZc%253D"></script>

In this case there is no function that you can call in a control. The file call as you will note is parameter based.

Please assist.

Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: javascript file call in Visual C# asp.net code

#2 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 203
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: javascript file call in Visual C# asp.net code

Posted 21 June 2010 - 06:16 AM

View Postsupertime2000, on 21 June 2010 - 02:41 AM, said:

But how do you go about calling the following javascript file call in a Visual C# asp.net code?:

<script type="text/javascript" src="http://www.benchmarkemail.com/code/lbform.js?mFcQnoBFKMSnJvV2CKpXy%252BoNbCMyivkXsgDgIhejGZc%253D"></script>

In this case there is no function that you can call in a control. The file call as you will note is parameter based.


What do you mean by a "Javascript file call in a C# Asp.NET code"?
Is the Javascript file embedded into the application?

I'm not sure what you are trying to do with the src attribute in the <script> code that you posted....could you please elaborate on what you are attempting to do here?

-Frinny
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: javascript file call in Visual C# asp.net code

Posted 21 June 2010 - 06:22 AM

I'm (like Frinny here) 100% sure what you're asking here, but with using Page.RegisterClientScriptBlock would be the same

Page.RegisterClientScriptBlock("MyScript", _
<script type="text/javascript" src="http://www.benchmarkemail.com/code/lbform.js?mFcQnoBFKMSnJvV2CKpXy%252BoNbCMyivkXsgDgIhejGZc%253D"></script>)



NOTE: Page.RegisterClientScriptBlock is obsolete and you should be using ClientScriptManager.RegisterClientScriptBlock
Was This Post Helpful? 0
  • +
  • -

#4 Guest_Anand*


Reputation:

Re: javascript file call in Visual C# asp.net code

Posted 21 June 2010 - 07:00 PM

Thank you all for a prompt response.

I could achieve my objective through placing the following code in the Page_Load event:

Page.ClientScript.RegisterClientScriptInclude("MyScript", "http://www.benchmarkemail.com/code/lbform.js?mFcQnoBFKMSnJvV2CKpXy%252BoNbCMyivkXsgDgIhejGZc%253D");

I am now looking to position the run time image generated by this script at the place of my choice in page. Any suggestions?

Thank you.
Was This Post Helpful? 0

#5 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 203
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: javascript file call in Visual C# asp.net code

Posted 22 June 2010 - 07:11 AM

I'm assuming that you were able to somehow get this to work even though your code doesn't make any sense at all....

So I'll answer your second question: how do you position an image in the page?

You do this using CSS to position the HTML <img> element that is displaying the image. (Remember that ASP.NET Image controls are rendered as <img> HTML elements)

But I think your problem is that you are not using the <img> tag to display the image...that the image is taking up the whole window. If I'm right then you need to change your code and use the ASP.NET Image control to display your image.

-Frinny
Was This Post Helpful? 0
  • +
  • -

#6 supertime2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-February 10

Re: javascript file call in Visual C# asp.net code

Posted 22 June 2010 - 07:50 PM

Thank you Frinny. I will clarify.

To make javascript file call, from a custom server control:

The first step would be to create a literal control in the current ascx file ( I am assuming that you are using a server control here ).
Paste the code below in the ascx file
<asp:Literal id="ltBMESignupForm" runat="server" />
in the code behind of the ascx file which should be ascx.cs.
paste the following code into public override void LoadControl() method which should already be present there.

ltBMESignupForm.Text = "<script type=\"text/javascript\" src=\"http://www.benchmarkemail.com/code/lbform.js?mFcQnoBFKMSnJvV2CKpXy%252BoNbCMyivkXsgDgIhejGZc%253D\"></script>";

If you look at the example above you will see that the double quotes inside of the string have been replaced with \".

But since I do not plan to use a custom server control, my option is to use only the ClientScript property of a Page. Components such as Image that you have suggested do not offer this property.

And since this component becomes visual only at run time, I am back to the question as to how do I position it?

Thank you.
Was This Post Helpful? 0
  • +
  • -

#7 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 203
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: javascript file call in Visual C# asp.net code

Posted 22 June 2010 - 08:33 PM

Wait, go back.

First of all, writing a Javascript include into a Literal control is probably not a good idea. There are a whole bunch of reasons why.... but I'll just leave it at that.

Using the ClientScript property is a better idea but...this is obsolete.
You should be using the RegisterClientScriptBlock method instead.

Please be aware that if your Server Control is ever going to be used in an Ajax enabled page, this won't work either. You will have to register it with the ScriptManager instead.

Now...you haven't actually explained what the server control does.
Apparently images are involved... There is no reason why the image cannot be displayed in an Image Control. All you have to do is add it to your server control.

It would be a good idea to share with me what your server control does so that I can help you further (right now I have no idea what you're trying to do)

-Frinny
Was This Post Helpful? 0
  • +
  • -

#8 supertime2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-February 10

Re: javascript file call in Visual C# asp.net code

Posted 22 June 2010 - 09:30 PM

Frinny, you are prompt. Thanks.

RegisterClientScriptBlock method is a good solution when you know a specific function that you are calling in a script. In this case, I am only querying the script through a parameter. In absence of a function name, how do you incorporate a registered client script in a component such as image?

I am considering a custom server control only since none of the UI controls offer a LoadControl() method to me.

Thank you.
Was This Post Helpful? 0
  • +
  • -

#9 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 203
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: javascript file call in Visual C# asp.net code

Posted 22 June 2010 - 10:09 PM

You know, I still do not understand your problem.
You just said that you are querying the script through a parameter but that's not what you're doing.

This is what you posted:

<script type="text/javascript" src="http://www.benchmarkemail.com/code/lbform.js?mFcQnoBFKMSnJvV2CKpXy%252BoNbCMyivkXsgDgIhejGZc%253D"></script>

I guess what is confusing me the most is "lbform.js" because it ends in ".js"

The .js extension is reserved for Javascript files.
If the "lblform.js" is not a Javascript file (and it's some sort of aspx page that dynamically generates Javascript) then this might help me to understand your design.

Right now, I am very confused because you cannot pass a parameter into a Javascript file. It's just.....not possible at all.

However, you can pass parameters (using the Query String) into server side pages (like aspx pages, or PHP pages...)

I cannot help you if I do not understand what you're doing...I need you to clarify what you are doing.

-Frinny
Was This Post Helpful? 0
  • +
  • -

#10 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: javascript file call in Visual C# asp.net code

Posted 22 June 2010 - 10:13 PM

I'm about as confused as Frinny on this one. Why not post the code from bform.js (inside code tags for Gods sake) so we might be able to decipher what you're after, because you're not doing a good job on explaining it at this point :)
Was This Post Helpful? 0
  • +
  • -

#11 supertime2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-February 10

Re: javascript file call in Visual C# asp.net code

Posted 23 June 2010 - 01:19 AM

Friends, I am an end user application specialist who programs and not vice verse. Regret to have confused you through calling ?mFcQnoBFKMSnJvV2CKpXy%252BoNbCMyivkXsgDgIhejGZc%253D, a parameter.

The essence of my premise is that I can not use RegisterClientScriptBlock since I have no function that I can call in my UI component.

http://www.benchmark...gDgIhejGZc%253D

is all the code I have and any solution must take this fact into account. I have no code content for lbform.js available with me at all.

Thank you.
Was This Post Helpful? 0
  • +
  • -

#12 supertime2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-February 10

Re: javascript file call in Visual C# asp.net code

Posted 23 June 2010 - 01:52 AM

Attached please find a file carrying code listing that I get on calling:

http://www.benchmark...gDgIhejGZc%253D

in the browser instead of running it as a javascript.

Thank you.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#13 supertime2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-February 10

Re: javascript file call in Visual C# asp.net code

Posted 23 June 2010 - 08:24 PM

Page positioning of run time javascript runtime image achieved. This is how:

protected void Page_Load(object sender, EventArgs e)
{
Literal l = new Literal();
l.Text = "<script type=\"text/javascript\" src=\"http://www.benchmarkemail.com/code/lbform.js?mFcQnoBFKMSnJvV2CKpXy%252BoNbCMyivkXsgDgIhejGZc%253D\"></script>";
this.Panel1.Controls.Add(l);
}

Friends, Thank you for your participation.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1