Too many characters in character literal while calling javascript function.


I wanna call the java script function when a gridview's link is clicked.
The link is dependent on the query string value of the row.
I am using the the template column in the gridview as below code,

       <a style="color: Blue" href="javascript:gotoURL(this,<%#GetURl(DataBinder.Eval(Container.DataItem,'id'))%>);">
               <%#GetMove(DataBinder.Eval(Container.DataItem,'M_Number').ToString())%> //This is the link that appears to the users.

My java script function is below,

 function gotoURL(dl,Id)
            var urlString=dl.document.form1.DropDownListReports.options[dl.document.form1.DropDownListReports.selectedIndex].value;

I am getting the following error at these two lines.

<a style="color: Blue" href="javascript:gotoURL(this,<%#GetURl(DataBinder.Eval(Container.DataItem,'id'))%>);">

Too many characters in character literal.

Can anybody guess what would have gone wrong.

Imagination is more important than knowledge..
[Albert Einstein]


4/23/2008 1:16:20 PM 93655 articles. 5 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 40

To bind a property/attribute, you must use single quotes on the outside and double quotes for strings.  Your lines of code can be shortened to:


<a style="color: blue" href='<%# "javascript:gotoURL(this," & GetURl(Eval("id")) & ");" %>'>
<%# GetMove( Eval("M_Number").ToString() )%>
MCP - Web Based Client Development .NET 2.0
4/23/2008 2:50:06 PM

What is the nature of the columns ID and M_Number, is any of these columns a varchar Column (text) and does any of the values in these contain double quotes?

If yes then your href would not be closed properly it would look something like this when rendered

<a style="color: Blue" href="javascript:gotoURL(this,123"123">, while 123"123 is an example of the ID that has a double quote there somewhere.

From a security prespective, the datam from M_Number should be clean, if the end user is allowed to fill in or manipulate this data, your website could be vunlerable to XSS attacks. Be careful.

Let me know if this helps.

My Blog
If you get the answer to your question, please mark it as the answer.
4/23/2008 2:58:05 PM

Similar Artilces:

Too many characters in character literal in javascript!!!
Hi All: I have code:string MyCust_Code = e.Row.Cells.FromKey("CusCode").ToString(); e.Row.Cells.FromKey("CusName").Value = "<span style='cursor:hand' onclick='javascript:PopupCampaign_Test('" + MyCust_Code + "');'><font color='#0000ff'>" + e.Row.Cells.FromKey("CusName").ToString() + "</font></span>"; And PopupCampaign_Test Javascript function:function PopupCampaign_Test(stringrequest) {mywindow ='../LGPopup/SearchCampaignReload.aspx?MyCus_Code='+strin...

too many characters in character literal
I have this javascriptfunction kolla(hal) {  alert(document.getElementById('<%=txtHole'+hal+'Points.ClientID%>').value);     } the errormessage from VS2005 is too many characters in character literal   the functioncall is txtHole1Strokes.Attributes.Add("onchange", "kolla('1');");   how can i change the string?   also, this is ok document.getElementById('<%=txtHole8Strokes.ClientID%>').value;   // Regards Tomas  alert(document.getElementById('<%=txtHole %>'...

Error: Too many characters in character literal
Hi. I'm tryingout the CallBack Event handling code from here:   I'm using C#.   My problem is when I build the website I get error: "Too many characters in character literal" for line <asp:DropDownList ID="ParentDropDown" OnSelectedIndexChanged="GetChildren(this.options[this.selectedIndex].value, 'ddl')" Runat="server"> Please help. Thanks! You are missing ";" in  OnSelectedIndexChanged.. Try this. <asp:DropDownList ID="ParentDropDown" OnSe...

Why am I getting "Too many characters in character literal" here?
Why am I getting "Too many characters in character literal" here? <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> I checked another project that compiles, and the line above is exactly the same...?Clay Shannon,author of historical works, novels, and art/poetry Are you sure that's the line causing the error?That error usually happens when you use single quotes when you should have used double quotes. Please Mark As Answer posts that ...

Error Message from HyperLink control : Too many characters in character literal
Hi all, I can getting this error message from the HyperLink control for some reason when using the following code:<asp:HyperLink     CssClass="text"     NavigateUrl="clients.aspx?CatType=<%# DataBinder.Eval(Container.DataItem, 'au_id')%>"     Text="<%# DataBinder.Eval(Container.DataItem, 'au_fname') %>"     Runat="server"     ID="HyperLink1" />Now I think the problem is because I am using single quotes and ASP.NET assuming its a Char (am I right here?), so if I replace these single quotes with double...

how many form they exist to call a Web Service, from VS.NET
An form, is add Web Reference, with the url of Web Service. can I also call it using the global.asax file.MCP Sergio Tarrillo Yes you can. After you add the web reference, it would create a proxy call. So, you could use that class and its methods like any other class from various places of your applicationKumar Reddi Don't used AddRefrence Web. what another form I can use?. MCP Sergio Tarrillo...

"Newline in constant" and "Too many characters in character literal" errors. Dataadapters and datatables.
I'm getting the above errors on line 41 (parameter delcaration)... been hitting my head on this for a while.. please help.  public static DataTable dtCleanVendorUsers(string username) {SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["VendorEvaluationConnectionString"].ConnectionString); SqlDataAdapter dataadapter = new SqlDataAdapter();dataadapter.SelectCommand = new SqlCommand("SELECT vendoruser_user_id, vendoruser_vendor_id, user_name, vendor_name, vendor_evaluated FROM vwVendorUsers WHERE (vendor_evaluated = 0) and (u...

Acessing variables, objects and functions from javascript to VB .NET Web Forms
I have included some javascript files in my application. I want to access the variables, objects and functions of Javascript to the VB.NET Web Forms, which means that I want to transfer the methods from Javascript to the code-behind in a web form. How do I do this? Can anybody help me with some sample codes...thanks in advance . you can't pass javascript variables (client side) to code-behind (server side). you can however put your variables into hidden input fields then access those input fields from code-behind. or use ajax I think the only way to do this is...

Funny character being added instead of spaces in .net web forms...please help
Hi,in all of my pages I have the following html code:&nbsp;&lt;TD class=padding colSpan=2 height=23&gt;&lt;div align="center"&gt;&lt;A &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; href="#"&gt;Privacy Policy&lt;/A&gt; »&lt;a href="#"&gt; Terms of Use&lt;/a&gt;&lt;/div&gt;&lt;/TD&gt;on my default.aspx page, this gets displayed as: Privacy Policy » Terms of Useand the code isPrivacy Policy » Terms of UseCan ...

Acessing variables,arrays, objects and functions from javascript to VB .NET Web Forms
I have a textbox where user can put data.I store data into an array .I did this with java i want to acess the array from the Codebehind  in web is the codefunction MakeArray( n ) { if( n <= 0 ) { this.length = 0; return this; } this.length = n; for( var i = 1; i <= n; i++ ) { this[ i ] = 0; } return this; } var Form1 = new MakeArray( 25 ); var index = 0; var cmmnd = 1; function f_store( sTR ) { var i; if( index >= Form1.length ) { for( i = 1; i < Form1.length; i++ ) Form1[i-1] = Form1; index = Form1.length - 1; } Form1[ index ] = cmmnd + ":" + sT...

How to call AJAX function from a PowerBuilder 11.5 .NET Web Forms application?
Dear All, I would like to know if it is possible (if yes then how) to call AJAX function from a PowerBuilder 11.5 .NET Web Forms application. Any pointer or information is much appreciated. Thank you very much in advance. Thanks and Best Regards, Jessica The first thing you need to do is install the AJAX Extensions for ASP.Net. They can be downloaded here: You write a client-side JavaScript event handler - say myScriptFile.js. Then, in the PowerBuilder ...

too many characters in literal
thats my javascript error it wont build and this is my code <input type="hidden" runat="server" id="hdnAddInfoIndex" /> <asp:RadioButtonList ID="rblOffers" runat="server" AutoPostBack="false" OnSelectedIndexChanged="CheckAdditionalInfo('rblOffers')" > </asp:RadioButtonList>  function CheckAdditionalInfo(rbList) {var needAdditionalInfo = new Array(); var selectedValue = '';var radiobuttonlist = document.getElementById(rbList);needAdditionalInfo = document.getElementById("h...

calling a web form from another web form
I would like to know what is the best way to open a web form from another web form. I would like to call it from a button control. Thanks Well, if I've grasped your question right, there are many methods to do that: 1)Response.Redirect > To navigate to another page from code and is equal to clicking a hyperlink. I suggest this as I think it's closer to your question. 2)Server.Transfer > This ends the current web form and begins a new web form. It's usable when you want to pass some variables i.e (Label1.Text) to the next immediate page. It's not safe though and not used to send p...

superreview granted: [Bug 260660] RDFServ nspr logging for literals prints out a single character : [Attachment 159530] print more than a single character of the literal
Daniel Veditz <> has granted (working) <>'s request for superreview: Bug 260660: RDFServ nspr logging for literals prints out a single character Attachment 159530: print more than a single character of the literal ------- Additional Comments from Daniel Veditz <> sr=dveditz ...

Web resources about - Too many characters in character literal while calling javascript function. -

Dilbert (character) - Wikipedia, the free encyclopedia
Dilbert is a fictional character and the main character and protagonist of the Dilbert comic strip . He is a white collar office worker who has ...

New Zealanders who failed Australia's 'character test' returned: Peter Dutton
Twelve New Zealanders have left Australia after failing a &quot;character test&quot; as the federal government cracks down on foreign criminals. ...

Standard Of Review: Legal Novel ‘Motor City Shakedown’ Is Undermined By Romance Between Its Main Characters ...
Pop quiz, hotshot: name a thriller in which the two main characters become romantically involved but the romance does not feel clumsy or tacked ...

Sainsbury's Brings Beloved Kids' Character to Life and Tops U.K. Book Sales
This week saw an unexpected new title shoot to the top of the U.K's official book charts: "Mog's Christmas Calamity," by children's author Judith ...

Friday Evening Open Thread: Cartoons & Cartoon Characters
Charlie Hebdo's new cover: "They've got guns. Screw them, we've got champagne" — Katy Lee (@kjalee) November 17, ...

Building Brands With Character And Chemistry
No review of the brand Jordan phenomenon would be complete without examining the extraordinary creative collaboration that Michael had with Nike’s ...

George Lucas says if he could be any 'Star Wars' character, he'd be Jar Jar Binks
Of all the characters in "Star Wars," creator George Lucas says he'd be Jar Jar Binks in a v ideo for Vanity Fair . "I like all the characters," ...

The Walking Dead: is that character still alive and was there a clue?
Spoilers for the last episode of Walking Dead follow Last night’s Walking Dead was yet another capsule episode, as we’ve come to expect, and ...

Epic reveals another character for Paragon, still won't tell us what the game is
... the game's roster, but has neglected to tell us anything of substance about it. All in due time, I suppose. Sparrow is the third of five characters. ...

Bye-Bye, Carrie Bradshaw! Sarah Jessica Parker Debuts New Character for HBO Comedy 'Divorce'
Sarah Jessica Parker is once again strutting the streets of New York City, but this time it's for her new HBO comedy, 'Divorce'.

Resources last updated: 11/21/2015 7:29:55 PM