Connecting Tech Pros Worldwide Forums | Help | Site Map

QueryString and Client-side error

VancouverMike
Guest
 
Posts: n/a
#1: Mar 27 '06
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.as...900-01-01&sx=m

Any idea?

Thanks a lot.

Mike

Phillip Williams
Guest
 
Posts: n/a
#2: Mar 27 '06

re: QueryString and Client-side error


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.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"VancouverMike" wrote:
[color=blue]
> 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.as...900-01-01&sx=m
>
> Any idea?
>
> Thanks a lot.
>
> Mike[/color]
VancouverMike
Guest
 
Posts: n/a
#3: Mar 27 '06

re: QueryString and Client-side error


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


"Phillip Williams" wrote:
[color=blue]
> 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.
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "VancouverMike" wrote:
>[color=green]
> > 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.as...900-01-01&sx=m
> >
> > Any idea?
> >
> > Thanks a lot.
> >
> > Mike[/color][/color]
Phillip Williams
Guest
 
Posts: n/a
#4: Mar 27 '06

re: QueryString and Client-side error


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.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"VancouverMike" wrote:
[color=blue]
> 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
>
>
> "Phillip Williams" wrote:
>[color=green]
> > 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.
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "VancouverMike" wrote:
> >[color=darkred]
> > > 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.as...900-01-01&sx=m
> > >
> > > Any idea?
> > >
> > > Thanks a lot.
> > >
> > > Mike[/color][/color][/color]
VancouverMike
Guest
 
Posts: n/a
#5: Mar 27 '06

re: QueryString and Client-side error


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,"MemberAcco unt")%>",
"<%#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);
}
}
}
--------------------------------------------------------------------------------------------------------------------



"Phillip Williams" wrote:
[color=blue]
> 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.
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "VancouverMike" wrote:
>[color=green]
> > 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
> >
> >
> > "Phillip Williams" wrote:
> >[color=darkred]
> > > 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.
> > > --
> > > HTH,
> > > Phillip Williams
> > > http://www.societopia.net
> > > http://www.webswapp.com
> > >
> > >
> > > "VancouverMike" wrote:
> > >
> > > > 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.as...900-01-01&sx=m
> > > >
> > > > Any idea?
> > > >
> > > > Thanks a lot.
> > > >
> > > > Mike[/color][/color][/color]
Phillip Williams
Guest
 
Posts: n/a
#6: Mar 27 '06

re: QueryString and Client-side error


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")))%>

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"VancouverMike" wrote:
[color=blue]
> 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,"MemberAcco unt")%>",
> "<%#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);
> }
> }
> }
> --------------------------------------------------------------------------------------------------------------------
>
>
>
> "Phillip Williams" wrote:
>[color=green]
> > 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.
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "VancouverMike" wrote:
> >[color=darkred]
> > > 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
> > >
> > >
> > > "Phillip Williams" wrote:
> > >
> > > > 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.
> > > > --
> > > > HTH,
> > > > Phillip Williams
> > > > http://www.societopia.net
> > > > http://www.webswapp.com
> > > >
> > > >
> > > > "VancouverMike" wrote:
> > > >
> > > > > 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.as...900-01-01&sx=m
> > > > >
> > > > > Any idea?
> > > > >
> > > > > Thanks a lot.
> > > > >
> > > > > Mike[/color][/color][/color]
VancouverMike
Guest
 
Posts: n/a
#7: Mar 27 '06

re: QueryString and Client-side error


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




"Phillip Williams" wrote:
[color=blue]
> 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")))%>
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "VancouverMike" wrote:
>[color=green]
> > 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,"MemberAcco unt")%>",
> > "<%#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);
> > }
> > }
> > }
> > --------------------------------------------------------------------------------------------------------------------
> >
> >
> >
> > "Phillip Williams" wrote:
> >[color=darkred]
> > > 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.
> > > --
> > > HTH,
> > > Phillip Williams
> > > http://www.societopia.net
> > > http://www.webswapp.com
> > >
> > >
> > > "VancouverMike" wrote:
> > >
> > > > 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
> > > >
> > > >
> > > > "Phillip Williams" wrote:
> > > >
> > > > > 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.
> > > > > --
> > > > > HTH,
> > > > > Phillip Williams
> > > > > http://www.societopia.net
> > > > > http://www.webswapp.com
> > > > >
> > > > >
> > > > > "VancouverMike" wrote:
> > > > >
> > > > > > 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.as...900-01-01&sx=m
> > > > > >
> > > > > > Any idea?
> > > > > >
> > > > > > Thanks a lot.
> > > > > >
> > > > > > Mike[/color][/color][/color]
Phillip Williams
Guest
 
Posts: n/a
#8: Mar 28 '06

re: QueryString and Client-side error


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,"L astName").ToString())%>'

Escaping the quotation mark means that the Javascript will not choke on it.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"VancouverMike" wrote:
[color=blue]
> 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
>
>
>
>
> "Phillip Williams" wrote:
>[color=green]
> > 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")))%>
> >
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "VancouverMike" wrote:
> >[color=darkred]
> > > 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,"MemberAcco unt")%>",
> > > "<%#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);
> > > }
> > > }
> > > }
> > > --------------------------------------------------------------------------------------------------------------------
> > >
> > >
> > >
> > > "Phillip Williams" wrote:
> > >
> > > > 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.
> > > > --
> > > > HTH,
> > > > Phillip Williams
> > > > http://www.societopia.net
> > > > http://www.webswapp.com
> > > >
> > > >
> > > > "VancouverMike" wrote:
> > > >
> > > > > 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
> > > > >
> > > > >
> > > > > "Phillip Williams" wrote:
> > > > >
> > > > > > 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.
> > > > > > --
> > > > > > HTH,
> > > > > > Phillip Williams
> > > > > > http://www.societopia.net
> > > > > > http://www.webswapp.com
> > > > > >
> > > > > >
> > > > > > "VancouverMike" wrote:
> > > > > >
> > > > > > > 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.as...900-01-01&sx=m
> > > > > > >
> > > > > > > Any idea?
> > > > > > >
> > > > > > > Thanks a lot.
> > > > > > >
> > > > > > > Mike[/color][/color][/color]
intrader
Guest
 
Posts: n/a
#9: Mar 28 '06

re: QueryString and Client-side error


On Mon, 27 Mar 2006 12:14:02 -0800, VancouverMike wrote:
[color=blue]
> 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.as...900-01-01&sx=m
>
> Any idea?
>
> Thanks a lot.
>
> Mike[/color]
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....


VancouverMike
Guest
 
Posts: n/a
#10: Mar 31 '06

re: QueryString and Client-side error


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


"Phillip Williams" wrote:
[color=blue]
> 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,"L astName").ToString())%>'
>
> Escaping the quotation mark means that the Javascript will not choke on it.
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "VancouverMike" wrote:
>[color=green]
> > 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
> >
> >
> >
> >
> > "Phillip Williams" wrote:
> >[color=darkred]
> > > 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")))%>
> > >
> > > --
> > > HTH,
> > > Phillip Williams
> > > http://www.societopia.net
> > > http://www.webswapp.com
> > >
> > >
> > > "VancouverMike" wrote:
> > >
> > > > 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,"MemberAcco unt")%>",
> > > > "<%#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);
> > > > }
> > > > }
> > > > }
> > > > --------------------------------------------------------------------------------------------------------------------
> > > >
> > > >
> > > >
> > > > "Phillip Williams" wrote:
> > > >
> > > > > 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.
> > > > > --
> > > > > HTH,
> > > > > Phillip Williams
> > > > > http://www.societopia.net
> > > > > http://www.webswapp.com
> > > > >
> > > > >
> > > > > "VancouverMike" wrote:
> > > > >
> > > > > > 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
> > > > > >
> > > > > >
> > > > > > "Phillip Williams" wrote:
> > > > > >
> > > > > > > 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.
> > > > > > > --
> > > > > > > HTH,
> > > > > > > Phillip Williams
> > > > > > > http://www.societopia.net
> > > > > > > http://www.webswapp.com
> > > > > > >
> > > > > > >
> > > > > > > "VancouverMike" wrote:
> > > > > > >
> > > > > > > > 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.as...900-01-01&sx=m
> > > > > > > >
> > > > > > > > Any idea?
> > > > > > > >
> > > > > > > > Thanks a lot.
> > > > > > > >
> > > > > > > > Mike[/color][/color][/color]
Closed Thread