QueryString and Client-side error

G

Guest

Hi there,

I run into a very strange problem. I got the following url and am passing
information via query string. The problem when the "sin" key in query string
is blank, shown as in the following querystring, I got an error message
saying "Unterminated string constant" from IE 6.0 and asking me if I want to
debug. When I click Yes button, nothing happened and the page just shows up.
When I put anything as a value for "sin" key, IE doesn't complain. The
code-behind code is running without problem and I am not doing anything with
the sin in client side. I am wondering if it's the word "sin" not good, or
something else funny happening.

http://localhost/IDImaging/Assign.a...&sin=&fn=ty&mn=d&ln=WHATCOM&b=1900-01-01&sx=m

Any idea?

Thanks a lot.

Mike
 
G

Guest

Hi Mike,

Since we are both in Vancouver, :) I might suggest that you do not pass the
SIN in the querystring in web application, otherwise you might find someone
complaining about the confidentiality fo their private information.

As for the error that you got, it seems to be a javascript error that is
caused by an empty value in the querystring. Look into the Javascript that
runs this page and see where it is using the SIN.
 
G

Guest

Hi Phil,

Thanks for your reply. My web app will be run in an secured Intranet
environment so there is no risk for using SIN in querystring.

I think the problem is to have ampersand sign in javascript function
parameters. I am using SIN as a key to search database to get those matching
the given SIN customers and when I pass a blank SIN number, I got some
business customers with ampersand in their names. When I construct javascript
function calls by using these names, ampersand is in the function call code
and it seems it's the problem. Any suggestion to work around that?

Thanks,
Mike
 
G

Guest

If you post the lines of Javascript code that is causing the error I might be
able to suggest an alternative code avoids you this error.
 
G

Guest

Hi Phillip,

Please see the following TemplateColumn code for showing a column in
datagrid. It has a client side button with constructed javascript function
call for onclick event. If the LastName field from datasource has ampersand
in it, I think it will cause problem.

Thanks,
Mike

aspx file
----------------------------------------------------------------------------------------------------------------------------
<asp:TemplateColumn>
<ItemTemplate>
<b>Name: </b><%# GetWholeName(DataBinder.Eval(Container.DataItem,
"FirstName"), DataBinder.Eval(Container.DataItem, "MiddleName"),
DataBinder.Eval(Container.DataItem, "LastName"))%> <br/>
<b>Account: </b><%# DataBinder.Eval(Container.DataItem,
"ShortName")%> - <%# DataBinder.Eval(Container.DataItem,
"MemberAccount")%><br/>
<INPUT type="button" class="ViewIDImageButton" value="View ID Image" <%#
HasImage(DataBinder.Eval(Container.DataItem, "ImageId")) %>
onclick='ViewIDImage("<%#DataBinder.Eval(Container.DataItem,"ImageId")%>", "<%#DataBinder.Eval(Container.DataItem,"ShortName")%>",
"<%#DataBinder.Eval(Container.DataItem,"MemberAccount")%>",
"<%#DataBinder.Eval(Container.DataItem,"FirstName")%>",
"<%#DataBinder.Eval(Container.DataItem,"MiddleName")%>",
"<%#DataBinder.Eval(Container.DataItem,"LastName")%>");'/>
</ItemTemplate>
</asp:TemplateColumn>
--------------------------------------------------------------------------------------------------------

Code-behind file:
-----------------------------------------------------------------------------------------------------------
protected string HasImage(object objImageId)
{
string strId = objImageId.ToString();


if(strId == "")
{
return "disabled";
}

return string.Empty;
}

protected string GetWholeName(object objFirstName, object objMiddleName,
object objLastName)
{
string strFirstName = objFirstName.ToString();
string strMiddleName = objMiddleName.ToString();
string strLastName = objLastName.ToString();

if (strFirstName == "")
{
if (strMiddleName == "")
{
return strLastName;
}
else
{
return (strMiddleName + " " + strLastName);
}
}
else
{
if (strMiddleName == "")
{
return (strFirstName + " " + strLastName);
}
else
{
return (strFirstName + " " + strMiddleName + " " + strLastName);
}
}
}
 
G

Guest

Hi Mike,

If you have ampersand in a last name stored on the database, it means that
it is saved as HTMlEncoded. What you need to do is to send it in the
QueryString as URLEncoded instead. To understand the differences try this
test:
String strName = "Mike O"Connor";
//This will print the name in English
Response.Write(Server.HtmlDecode(strName)) ;
//this would print the name is a format that can be passed in URL
QueryString
Response.Write(Server.UrlEncode(Server.HtmlDecode(strText)));

So try enclosing your DataBinder expressions with Server.UrlEncode, e.g.

<%#
Server.UrlEncode(Server.HtmlDecode(DataBinder.Eval(Container.DataItem,"LastName")))%>
 
G

Guest

Hi Phillip,

I tried your solution. I still get the error message. When I looked at my
data carefully, I found that there are not only ampersand symbols but also
apostrophe symbols in LastName field. I think later one definitely is the
problem, as it interferes with my Javascript function call code.

onclick='ViewIDImage("XXX", "XXX", "XXX", "XXX", "XXX", "XX'X");'

If you look at the last parameter above, if it has an apos symbol in it, it
will terminate the string for onclick event and leave the rest of the code
hanging around so interpreter can not understand, then throw an error out.
Any solution or suggestion for this?

Thanks very much.

Mike
 
G

Guest

I would create a function that escapes the quotes out of the string, like this:
protected string EscapeQuotes(string input)
{
string ret= input.Replace (@"'",@"\'");
return ret;
}

and call it while you are databinding upon any field that can contain quotes
and that will be used in a JavaScript in your form:
'<%#
EscapeQuotes(DataBinder.Eval(Container.DataItem,"LastName").ToString())%>'

Escaping the quotation mark means that the Javascript will not choke on it.
 
I

intrader

Hi there,

I run into a very strange problem. I got the following url and am passing
information via query string. The problem when the "sin" key in query string
is blank, shown as in the following querystring, I got an error message
saying "Unterminated string constant" from IE 6.0 and asking me if I want to
debug. When I click Yes button, nothing happened and the page just shows up.
When I put anything as a value for "sin" key, IE doesn't complain. The
code-behind code is running without problem and I am not doing anything with
the sin in client side. I am wondering if it's the word "sin" not good, or
something else funny happening.

http://localhost/IDImaging/Assign.a...&sin=&fn=ty&mn=d&ln=WHATCOM&b=1900-01-01&sx=m

Any idea?

Thanks a lot.

Mike
I ran into a problem with 'ltv' ad a keyname in the querystring.
I had to a change its name to 'bugltv'. The problem is that &lt is
recognizezed as '<'. It is possible that something like this is going on
wiht stuff starting with &s....
 
G

Guest

Hi Phillip,

Thanks very much for your help.

I figured out that if I want to show string that has apostrophe in <td> tag
directly, I need to replace it to &apos;, whereas if it's in Javascript, I
need to replace it to be \'.

Now it's working.

Thanks,
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top