Javascript - Inject A Script URL Containing An Ampersand?
Feb 3, 2010
I have a server control that needs to programmatically inject a JavaScript reference into the page. It is to reference Microsoft's Bing map control which requires &s=1 to be appended to the script URL for use over SSL. The problem is that the .NET Framework encodes the attributes and changes the & to an & (verified with Reflector). At some point after that the & is removed altogether.
Desired script tag:
<script type="text/javascript"
src="https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&s=1">
</script>
Attempt 1:
var clientScriptManager = this.Page.ClientScript;
if (!clientScriptManager.IsClientScriptIncludeRegistered(this.GetType(), "BingMapControl"))
{
clientScriptManager.RegisterClientScriptInclude(
this.GetType(), "BingMapControl",
"https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&s=1");
}
Attempt 2:
HtmlGenericControl include = new HtmlGenericControl("script");
include.Attributes.Add("type", "text/javascript");
include.Attributes.Add("src",
"https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&s=1");
this.Page.Header.Controls.Add(include);
View 3 Replies
Similar Messages:
Jul 15, 2010
I have an Html Form that I want to set focus to when the page loads. What I have done is coded the Site.Master to run a javascript function on page load. That js function retrieves a hardcoded form name from the DOM and, if found, sets focus to an input field in that form.
[Code]....
View 2 Replies
Jan 14, 2011
As part of our app, user can save some data as XML on server which becomes RSS feed for them. Now some of the file user created have & in file name as BB&T_RSS.xml. So when user point this to [URL], they won't get his. I tried BB%26T.xml, BB&T.xml without any success with IE, Chrome
View 2 Replies
Dec 13, 2010
i want to put this text
€
in the text of a dropdownlistitem, so at runtime it will show the euro sign
but .net nicely escapes my code, and then it becomes this:
€
and that will show in my dropdownlist, and that's not what i want.
Any other way to show € £ etc in a dropdownlist is accepted too.
code:
private void FillDropDownCurrency(DropDownList ddl)
{
ddl.Items.Add(new ListItem() { Value = CurrencyConstants.CHF_CURRENCY_CODE, Text = CurrencyConstants.CHF_CURRENCY_SYMBOL, Selected = false });
ddl.Items.Add(new ListItem() { Value = CurrencyConstants.GBP_CURRENCY_CODE, Text = CurrencyConstants.GBP_CURRENCY_SYMBOL, Selected = false });
ddl.Items.Add(new ListItem() { Value = CurrencyConstants.EURO_CURRENCY_CODE, Text = CurrencyConstants.EURO_CURRENCY_SYMBOL, Selected = true });
ddl.Items.Add(new ListItem() { Value = CurrencyConstants.USD_CURRENCY_CODE, Text = CurrencyConstants.USD_CURRENCY_SYMBOL, Selected = false });
}
The CurrencyConstants.EURO_CURRENCY_SYMBOL is the € code
View 2 Replies
Sep 1, 2010
I have the need to add a javascript include to my ASP.NET page. The url of the javascript file has two key/value pairs in the query string. But the ampersand is being escaped and I don't want that.
Page.ClientScript.RegisterClientScriptInclude("myKey",
"https://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&s=1")
This results in the following HTML:
<script
src="https://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&s=1"
type="text/javascript"></script>
But what I really want is:
<script
src="https://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&s=1"
type="text/javascript"></script>
View 1 Replies
Feb 24, 2010
If I have an & in the URL I get a bad request. I have followed the instructions at [URL] but still no luck. If I remove
[Code]....
from web.config it works. Encoding the URL does not help.
View 7 Replies
Mar 17, 2010
I use the following string format to navigate between webpages:
String.Format(Eval("Hyper") + "?BUSINESSSTREAM={0}&Dealer={1}&LeadID={2}&Companyid={3}&SalesPerson={4}", Eval("BusinessStream"), Eval("Dealer"),Eval("leadId"),Eval("CompanyID"),Eval("SalesPerson"))
However the companyid is a text string and the company may have an "&" in it which I know will truncate the string. I have seen that this can be overcome by using "UrlEncode" [URL] However I cant solve the syntax.
View 10 Replies
Nov 8, 2010
I need to be able to navigate through the file system from an asp.net page and gather metadata on files, directories ... The simple code I've put together makes a list of directories/files in a given location and has everything displayed as a link button. My problem is with link buttons under which I have paths that include ampersands and blanks. Here's a sample of code:
[Code]....
The Response.Redirect("aPage.aspx?d="+ e.CommandArgument.ToString()); line has the problem ... the e.CommandArgument.ToString() shows a truncated path that stops just before the first ampersand detected. I tried escaping the ampersand with a backslash but it did not work ... somehow I guess it's not exactly the character that's causing the problem ..
View 3 Replies
Aug 11, 2014
I'm using the Google Places API to discover information on a restaurant. [URL] ....
I need my name parameter to contain an & because I am looking for D'Agostino's Pizza & Pub. But I am not sure what my URL needs to look like, because my requests are returning no matches. I am trying:
maps.googleapis.com/maps/api/place/nearbysearch/json?location=41.8957646,-87.6553512&radius=5000&types=restaurant|food&name=D'Agostino's Pizza %26 Pub&key=<mykey>. But is that even right?
I believe the search should return results, because in google if you type "D'Agostino's restaurant north ogden avenue Chicago IL", it's a perfect match there.
View 5 Replies
Jul 24, 2012
1. How to read a query string if the data contains a '&' in it.
E.g.:
Default.aspx?id=1275&msg=abc&cba
after reading the query stringÂ
id = 1275
msg = abc&cba
View 1 Replies
Nov 19, 2010
I have this simple regex string to validate emails. It worked fine until someone came along with an email address that contained an ampersand:
^(['_a-zA-Z0-9-]+)(.['_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+)(.[a-zA-Z0-9-]+)*(.[a-zA-Z]{2,5})$
how I can alter this to accept the & symbol? I have tried countless ways with no success.
View 4 Replies
Jun 23, 2010
I'm trying to connect to my sql server 2008 database and I'm using impersonation within my asp.net 3.5 application
<identity impersonate="true" userName="testUserName" password="test&test" />
Naturally the compiler won't compile until I use the escape character:
<identity impersonate="true" userName="testUserName" password="test&test" />
So it compiles, unfortunately when I run my app, it get this:
Parser Error Message: Could not create Windows user token from the credentials specified in the config file. Error from the operating system 'Logon failure: unknown user name or bad password.
Source Error:
<identity impersonate="true" userName="testUserName" password="test&test" />
View 1 Replies
Sep 29, 2010
I'm using Entity Framework 4 for a simple app and would like to bake my connection credentials into the following connection string:
<connectionStrings>
<add name="MyEntities"
connectionString="metadata=res://*/MyDataModel.csdl|res://*/MyDataModel.ssdl|res://*/MyDataModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=localhostDEV;Initial Catalog=MyDB;UserId=myUser;Password=jack&jill;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
</connectionStrings>
However, the password (which I cannot change) contains an ampersand. ASP.NET throws:
Configuration Error: An error occurred while parsing EntityName. Line XX, position YYY.
If I replace the ampersand in the password with &, I get a SqlException: Login failed for user 'myUser'. Usually this trick works, but I'm guessing that something is failing because this is technically a connection string inside a connection string.
What should I do here? Most of my classes include code like:
using (var context = new MyEntities()) {
// do work
}
Update: It turns out that the credentials I am using are a domain account, so what I really need is Integrated Security=True in the connection string rather than a password.
Encoding the ampersand as indicated in the accepted answer should work fine, though I haven't tested it.
View 3 Replies
Mar 8, 2011
i trying to inject js to page (to tags) by using ihttpmodule.but js isn't injected.
the page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MyTempProject._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
[Code]....
View 1 Replies
Mar 2, 2011
sqlparameter param = new sqlparameter("@Name", sqldbtype.varchar, 20);
param.value = "Chloé";
cmd.parameters.add(param);
int accountnumber = (int)cmd.executescalar();
View 8 Replies
Jun 30, 2010
Consider this abstract class
public abstract class Foo
{
public Injectable Prop {get;set;}
}
i have an application that i want to enhance and simultaneously refactor for simplicity.
I have over 100 classes that call some same stuff (e.g Class Injectable) and i am thinking that this behaviour can be abstracted and set to a base class, and everybody will inherit from this base class so as to remove copy/paste code.
However, i want to avoid copy/paste code in the spring configuration file by defining an Injectable object and then define a child object foreach and every class that inherits from Foo.
I am looking for a way to set the abstract class's properties and then all child elements to automatically get them via configuration. I want to avoid to make the abstract class like this:
[code]....
View 5 Replies
Jan 6, 2011
I had came acroos an open source a java applet. I wanted to know is there somehow I could create a script that could be distributed and the applet could be embedded in any website? I have been able to inject jquery and JS scripts into websites by placing a tag pointing to a Javascript file and placing it in the header of the page but I don't know how a java applet can be injected?
View 1 Replies
Nov 24, 2010
I would like to create a custom action filter attribute that adds a value in the HttpContext items that would be accessible during model binding.
I have tried to add it in the OnActionExecuting but it that seems the modelbinding is exectued before the filter. Maybe there's a method in the modelbinder that I could override that will be fired after the filter and use the value injected by my filter.
What I want to do, is to inject a validation context (the library I use for validation supports context, it is nvalid.net (www.nvalid.net) I would like to be able to place an attribute such as
[ValidationContext("Prevalidation")]
on my actionresult method, so that the validation that occurs in my custom model binder could know which context to use when doing the Validation. That's why I can't simply make a custom model binder.
View 2 Replies
May 23, 2010
I have a tricky problem and I'm not sure where in the view rendering process to attempt this. I am building a simple blog/CMS in MVC and I would like to inject a some html (preferably a partial view) into the page if the user is logged in as an admin (and therefore has edit privileges).
I obviously could add render partials to master pages etc. But in my system master pages/views are the "templates" of the CMS and therefore should not contain CMS specific <% %> markup. I would like to hook in to some part of the rendering process and inject the html myself.
how to do this in MVC? Where would be the best point, ViewPage, ViewEngine?
View 2 Replies
Mar 3, 2010
Say I got this .aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyPage.aspx.cs" Inherits="MyPage" %>
<script type="text/javascript">
//<!-- I want to inject a JSON string here, which is generated per side-request -->
function doStuffToMyData(){
// .....
}
</script>
how I can inject a JSON string here? I got no problem generating the string, or parsing it in the browser..
It could be there's an easier way to do this? I basically want to manipulate the looks of the side, depending on changes to this data, so I figured it would be easiest to have the data as a JSON string.
View 2 Replies
Aug 3, 2010
I have a simple, but probably common problem on how to inject HTML inside an ASP.NET MVC master page. I have a google analytics tracking code that sits on my master page. The code looks like this:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-1']);
_gaq.push(['_trackPageview']);
// need to inject ecommerce code here
(function () {
// google analytics code here
})();
I'm using ecommerce tracking and I want to inject the "cart" information in side this HTML on the receipt page (and ONLY on this page). So I do something like this:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-1']);
_gaq.push(['_trackPageview']);
<% if(ViewData["googleanalytics"]!=null) {%>
<%= ViewData["googleanalytics"] %>
<% } %>
(function () {
// google analytics code here
})();
Then in the controller, I have code that looks like this:
[HttpGet]
public ActionResult Receipt()
{
var receipt = // get receipt model
// get google analytics javascript. This function pulls
// the data from the receipt model
ViewData["googleanalytics"] = GetAnalyticsInfo(receipt);
return View(receipt);
}
View 4 Replies
Mar 17, 2010
I currently work on an in-house 'CMS' that is fairly old. It has one 'content' field where the html of a CKEditor is saved and presented to each content page.
What I would like to do is be able to replace some special tags with the output of a control. So for example:
The content string would be
[Code]....
Then, when rendering the page, replace the '[%LatestNews(to=2010/01/01)%]' with the result of a user control. The user control may contain a asp:Repeater control or something that lists the required content.
View 3 Replies
Jan 4, 2011
Recently, I had prepared a java applet for my browser. I wanted to know is there somehow I could create a script that could be distributed and the applet could be embedded in any website?
View 4 Replies
Oct 22, 2010
I have a httpmodule that contains a property.
The httpmodule is used in my web application. I want to set the property in the httpmodule when my application starts and not have the overhead of setting it everytime the module is called.
The value for the application is read from my app settings in the web.config.
The httpmodule resides in a seperate dll to the web application.
So I want to inject/set the property from my web application on application start.
View 1 Replies
Feb 15, 2010
I have a profile object in session with profile information for the currently logged in user. I wand to be able to inject it into my business classes so I can do validation etc in them without having to pass it in the parameter list in every method.
I have tried something like this in my ninject module:
Profile profile = HttpContext.Current.Session["Profile"] as Profile;
Bind<Profile>().ToConstant(profile).InTransientScope();
However it blows up with null reference when I do Kernel.Get() in my aspx. The BusinessObject takes a profile via the constructor. If I hard code the profile instead of using the HttpContext then everything seems to work. Not sure if ToConstant is the way to go, I am really looking for something that will get evaluated every time a new BusinessObject is created.
UPDATE
It seems that asking for injection to happen on a page level object inline is too soon for the session collection to be available. If I move in the Kernel.Get call to Page_Load it works just fine.
View 4 Replies