Stop The Tag Builder Escaping Single Quotes MVC 2
Oct 13, 2010
I have the following HtmlHelper method that I want to create a button that does a redirect with JavaScript:
public static string JavaScriptButton(this HtmlHelper helper, string value,
string action, string controller, object routeValues = null, object htmlAttributes = null)
{
var a = (new UrlHelper(helper.ViewContext.RequestContext))
.Action(action, controller, routeValues);
var builder = new TagBuilder("input");
builder.Attributes.Add("type", "submit");
builder.Attributes.Add("value", value);
builder.Attributes.Add("class", "button");
builder.Attributes.Add("onclick", string.Format("javascript:location.href='{0}'", a));
builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
return MvcHtmlString.Create(builder.ToString(TagRenderMode.SelfClosing)).ToString();
}
The problem is that the line that creates the onclick handler is getting escaped by the tagbuilder, the resulting html is: <input class="button" onclick="javascript:location.href=''" type="submit" value="Return to All Audits" />
View 1 Replies
Similar Messages:
Aug 12, 2010
System.Web.Script.Serialization.JavaScriptSerializer s = new System.Web.Script.Serialization.JavaScriptSerializer();
result = s.Deserialize<Hashtable>(data);
Error is thrown if data is "{a:""test" 123",b:"hello" }"
No error is thrown if data is "{a:"test 123",b:"hello" }"
How do I adjust the data string so that no error is thrown even when there are quotes?
View 1 Replies
Apr 14, 2010
im trying to import a CSV file, however a single quote has been used to enclose strings ie. 'aaaa','bbbbbb',ccccccc'
Im having problems because some strings contain commas or apostrophes ie... 'aaaa,aaa' , bbbbb'bbbb',
This is causing me trouble and i need to replace the enclosing character for all strings from a single quote to a double quote....
I dont have access to the source that the csv was generated from, I just have the CSV file..
View 1 Replies
Nov 30, 2010
Since both are acceptable by HTML as well as languages like ASP.NET and PHP when using attributes or strings, why is it that some people use single quotes and double quotes interchangeably? It is my understanding that it is syntactically correct to use double quotes where possible, single when you need to embed a double quote for inline logic. Is there something I am missing? For examples: HTML
<a href='[URL]
PHP
<? echo 'Hello World!'; ?>
ASP.NET
<form id='myForm' runat='server'></form>
View 7 Replies
Jul 25, 2010
I have a hyperlink in asp.net that I want to dynamically create. I also add additional attributes like onmouseover to call a javascript function. My problem is that instead of setting my attribute to
onmouseover="myJSFunc('param')"
it converts it to
onmouseover="myJSFunc('param')".
Any ideas how to get this to work in ASP.NET C#?
EDIT:
These controls are in a repeater. This is what I have in my code behind;
hypNav.Attributes.Add("onmouseover", "myJSFunc('" + divNav.ClientID + "')");
View 3 Replies
Nov 16, 2010
n my datatable i am retrieving values which contain single quotes. .(eg: paul's, john's, raj's 199:LOQ etc. .) i want to replace these values with ''(double single quotes), so that these records can be inserted in the sqlserver database. . all these values are in single column.
View 3 Replies
Sep 20, 2010
I am trying something apart of my boundries, is there any way to disable a single intem in dropdownlist or stop the ddl change event for a single item.
View 2 Replies
Mar 10, 2011
i have a problem with syntax in my query andi, i have this
sqlStmt =
"SELECT Chron.ID, Chron.EmpID, Chron.WDate, Chron.OrID, Emplo.FName, Emplo.LName, Emplo.ID AS Expr1, Emplo.NUser,
Emplo.Passw FROM Chron INNER JOIN Emplo ON Chron.EmpID = Emplo.ID WHERE (Emplo.ID ='" & s1 &
"'AND Chron.WDate ='" &
"'"& s2 &
"')"
my problem is with the sigle and the double quotes, i tried some different methods but nothing.
View 5 Replies
Aug 20, 2010
i am developed on simple user registeration application in that i gave address field .when i am trying to enter something like this (1st main,b'lore) but wont take while inserting.
my query is
sqlcommand cmd=new sqlcommand("insert into registeration_form(name,address)values('"+txtname.text+"','"+txt_address+"')",con);
how can i pass the quotes also to my query if any one know reply me.
View 1 Replies
Feb 2, 2010
Iam Facing the problem with Insert query in sql Server i want to insert value India's, Iam not unable insert 's in sql server DB.
View 17 Replies
May 7, 2015
In my database, there is a column "summary" with single quot in it.I am fetching this data inside Gridview. Data is shown inside Gridview as:
<summary>"
I want single quot to be shown inside Gridview as (')for that I tried to change the code as below:
<asp:GridView ID="GridView1" runat="server" Width="100%" BackColor="White" DataKeyNames="IssueId"
AutoGenerateColumns="False" AllowPaging="True" PageSize="8" CssClass="Grid" OnRowDataBound="GridView1_RowDataBound">
[code]....
View 1 Replies
Dec 18, 2010
why ''' is not getting converted to single quotes while using server.htmldecode()?
What is the best way to do the decoding while using '"'"?
View 1 Replies
Feb 16, 2011
Let's say I have a single table Product with ID and Name,I would like the user to search for a text - so I made:
.Where(item=>item.Contains(SearchText))
When the SearchText is "CD" - all is good. However, I would like to let the user search with % - like searching for : CD%BLUE - like Name should contain CD and after some char the word BLUE.The problem is that EF is escaping the % - and , by that , it search for literal %, not for the meaning of % in SQL.
View 11 Replies
Jan 25, 2011
I have an image control with the following string
[URL]
I want to replace string cleartext=imagePath.Replace("","/"); but the backslash causes a problem -- how can I replace the backslash?
View 2 Replies
May 28, 2010
I am importing a comma seperated, single quote delimited file based off of client specifications. The only problem is now the client is sending apostophes in the file and is throwing off the single quote delimiter.
For Example:
'FirstName','LastName'
'John','O'Grady'
I need to figure out somehow to escape or replace that character before it goes into my OLE dataset import and then handle it before it hits my SQL table. Here is my current process flow:
Save the file to the App_Data using a FileUpload control Build a schema.ini for the ' delimeter Import into a dataset using Microsoft Jet OLE Use a for loop to pick out the fields that I need and build an insert into SQL I was trying to replace the ' with an underscore but then ended up replacing the whole file instead of just the one in the name.
View 3 Replies
Jan 19, 2011
i have my own DLL (for the data access layer),,i use escaping characters technique to avoid the user input errors ,, but recently i decided to enhance my classes and using parametrized query to prevent all possible errors,Is the modification will be easy or difficult ??how to convert this way to use the parametrized query ..
View 1 Replies
Sep 17, 2010
what string builder command do in the asp.net cs file.
View 4 Replies
Mar 29, 2011
I am using the code below (simplified for this example) to post data to a SharePoint list
StringBuilder customerDoc = new StringBuilder();
customerDoc.Append("<Method ID='1' Cmd='New'>");
customerDoc.Append("<Field Name='Name'>" + Name + "</Field>");
customerDoc.Append("<Field Name='Age'>" + age + "</Field>");
customerDoc.Append("<Field Name='City'>" + city + "</Field>");
customerDoc.Append("<Field Name='Country'>" + country + "</Field>");
customerDoc.Append("</Method>");
XmlDocument xDoc = new XmlDocument();
XmlElement xBatch = xDoc.CreateElement("Batch");
xBatch.SetAttribute("OnError", "Continue");
xBatch.InnerXml = sb_method.ToString();
XmlNode xn_return = sharePoint.listsObj.UpdateListItems(ConfigurationManager.AppSettings["SaveCustomer"].ToString(), xBatch);
As you can see I am using a stringbuilder which isn't ideal so I wonder what I should use instead to create an XML string?
View 7 Replies
Jan 4, 2010
What is the difference between strings and string builder in asp.net?
View 3 Replies
Apr 28, 2010
SqlDataReader myreader;
myreader = cmmd.ExecuteReader();
StringBuilder sb = new StringBuilder();
sb.Append("<b>Vaccine</b> <b> Vaccination Date</b> <b> Vaccination Due Date</b> <b> Incomplete Vaccination </b> <b>Dose No.</b> <b> Remarks </b><br/><br/>");
while (myreader.Read())
{
sb.Append(myreader["VaccineID"]);
sb.Append(" ");
sb.Append(myreader["DateOFVaccine"]);
sb.Append(" ");
sb.Append(myreader["NextVaccinationDueDate"]);
sb.Append(" ");
sb.Append(myreader["AnyIncompleteImmunization"]);
sb.Append(" ");
sb.Append(myreader["DoseNumber"]);
sb.Append(" ");
sb.Append(myreader["Remark1"]);
sb.Append("<br/>");
}
lblDisplayDetails.Text = sb.ToString();
myreader.Close();
WHAT EXACTLY I WANT IS TO RETRIEVE DATA(may be from separate table) AND THEN DISPLAY THEM PUTTING SOME STYLE(font,color etc). Is retrieving from multiple table is possible in gridview ? I could use the DataReader, but how to display them in style(font,color etc)?
View 2 Replies
Mar 12, 2011
I am using LINQ to SQL in my application. I have some fields like textbox and checkbox in my form. when i enter any text in textbox it should search the data in the database. it should display in some control. Here i want to write query in LINQ I want to use predicate builder. If we are using sql server we have to write in stored procedure but i dont want in stored procedure. plz tell how to use predicate builder and explaination.
View 1 Replies
Jan 11, 2010
I need to get rid of Microsoft smart quotes in my code behind page. I'm sure this is simple, but its new to me.
View 7 Replies
Aug 26, 2010
I need to post an xml string to another website. I can't create an xml file, because some of the content is dynamically created. The two lines that are causing me problems are
sPostData = sPostData & "<?xml version='1.0'?>"
sPostData = sPostData & "<?qbmsxml version='4.1'?>"
The receiving site expects to see
<?xml version="1.0"?>
<?qbmsxml version="4.1"?>
not
<?xml version='1.0'?>
<?qbmsxml version='4.1'?>
The conversion from double quotes to single quotes isn't being accepted. So how can I send the string so that the versions are surrounded by double quotes?
View 1 Replies
Oct 13, 2010
I'm trying to get my URLs to contain double quotes (") and other special characters such as <, > etc in my MVC2 application. Here's an example:
[URL]
The above would throw up a System.ArgumentException: Illegal characters in path.
View 4 Replies
Jun 29, 2010
I have written such a code to loop through the records and build a string.
Is this s good idea or should I use repeater or something?
[code]....
View 5 Replies