javascript file call in Visual C# asp.net codeAbout programming a javascript file call in Load event of a control
Page 1 of 1
12 Replies - 6963 Views - Last Post: 23 June 2010 - 08:24 PM
#1
javascript file call in Visual C# asp.net code
Posted 21 June 2010 - 03:41 AM
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.
Replies To: javascript file call in Visual C# asp.net code
#2
Re: javascript file call in Visual C# asp.net code
Posted 21 June 2010 - 06:16 AM
supertime2000, on 21 June 2010 - 02:41 AM, said:
<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
#3
Re: javascript file call in Visual C# asp.net code
Posted 21 June 2010 - 06:22 AM
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
#4 Guest_Anand*
Re: javascript file call in Visual C# asp.net code
Posted 21 June 2010 - 07:00 PM
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.
#5
Re: javascript file call in Visual C# asp.net code
Posted 22 June 2010 - 07:11 AM
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
#6
Re: javascript file call in Visual C# asp.net code
Posted 22 June 2010 - 07:50 PM
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.
#7
Re: javascript file call in Visual C# asp.net code
Posted 22 June 2010 - 08:33 PM
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
#8
Re: javascript file call in Visual C# asp.net code
Posted 22 June 2010 - 09:30 PM
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.
#9
Re: javascript file call in Visual C# asp.net code
Posted 22 June 2010 - 10:09 PM
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
#10
Re: javascript file call in Visual C# asp.net code
Posted 22 June 2010 - 10:13 PM
#11
Re: javascript file call in Visual C# asp.net code
Posted 23 June 2010 - 01:19 AM
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.
#12
Re: javascript file call in Visual C# asp.net code
Posted 23 June 2010 - 01:52 AM
http://www.benchmark...gDgIhejGZc%253D
in the browser instead of running it as a javascript.
Thank you.
Attached File(s)
-
lbform.txt (4.42K)
Number of downloads: 179
#13
Re: javascript file call in Visual C# asp.net code
Posted 23 June 2010 - 08:24 PM
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.
|
|

New Topic/Question
Reply




MultiQuote



|