473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

problem formatting URL in script

hi-

I have <a> tags in my DataList. For the href property, I want to do
something like this:
<a href='~/Default.aspx?show=Support&disp=Faq&p=<%#
DataBinder.Eval(Container.DataItem, "name")%>' runat=server>some link</a>

Looks pretty straight forward, but when I add the runat=server property it
stops parsing the <% %> block correctly.

The workaround has been to make a method that will take 2 strings,
concatentate them, then return the result, something like this:
public string BuildUri(string a, string b)
{
return a + b;
}

then in the <a> tag I do this:
<a href='<%#BuildUri("~/Default.aspx?show=Support&disp=Faq&p=",
DataBinder.Eval(Container.DataItem, "name"))%>' runat=server>some link</a>
That works. It's a pain though cuase a) I don't understand why I need to do
it in the first place and b) my needs have changed, sometimes I will be
combining 2,3 even 4 strings to form the URI, seems dumb to have 4
overloaded methods that take more and more strings ;)
So, what is causing this? This must have come up in the past. I tried
searching google, but I'm not sure what terms to use to describe the
problem.

If anyone has a solution (other than a function), I would love to hear it.
Thanks.

-Steve
Nov 18 '05 #1
7 1295
Why do you need a runat tag for anchor tags? Since it is
inside the Datalist control,which has a runat tag I dont
think you need a runat tag for Anchor links.

Thanks,
-Shan
-----Original Message-----
hi-

I have <a> tags in my DataList. For the href property, I want to dosomething like this:
<a href='~/Default.aspx?show=Support&disp=Faq&p=<%#
DataBinder.Eval(Container.DataItem, "name")%>' runat=server>some link</a>
Looks pretty straight forward, but when I add the runat=server property itstops parsing the <% %> block correctly.

The workaround has been to make a method that will take 2 strings,concatentate them, then return the result, something like this:public string BuildUri(string a, string b)
{
return a + b;
}

then in the <a> tag I do this:
<a href='<%#BuildUri("~/Default.aspx? show=Support&disp=Faq&p=",DataBinder.Eval(Container.DataItem, "name"))%>' runat=server>some link</a>

That works. It's a pain though cuase a) I don't understand why I need to doit in the first place and b) my needs have changed, sometimes I will becombining 2,3 even 4 strings to form the URI, seems dumb to have 4overloaded methods that take more and more strings ;)
So, what is causing this? This must have come up in the past. I triedsearching google, but I'm not sure what terms to use to describe theproblem.

If anyone has a solution (other than a function), I would love to hear it.Thanks.

-Steve
.

Nov 18 '05 #2
It's not an Anchor Tag, it's a reg. <a href> tag, I need the runat cause I'm
using the '~' to get to the VirtualRoot (dev server vs prod. server)
"Shan" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
Why do you need a runat tag for anchor tags? Since it is
inside the Datalist control,which has a runat tag I dont
think you need a runat tag for Anchor links.

Thanks,
-Shan
-----Original Message-----
hi-

I have <a> tags in my DataList. For the href property, I

want to do
something like this:
<a href='~/Default.aspx?show=Support&disp=Faq&p=<%#
DataBinder.Eval(Container.DataItem, "name")%>'

runat=server>some link</a>

Looks pretty straight forward, but when I add the

runat=server property it
stops parsing the <% %> block correctly.

The workaround has been to make a method that will take 2

strings,
concatentate them, then return the result, something like

this:
public string BuildUri(string a, string b)
{
return a + b;
}

then in the <a> tag I do this:
<a href='<%#BuildUri("~/Default.aspx?

show=Support&disp=Faq&p=",
DataBinder.Eval(Container.DataItem, "name"))%>'

runat=server>some link</a>


That works. It's a pain though cuase a) I don't

understand why I need to do
it in the first place and b) my needs have changed,

sometimes I will be
combining 2,3 even 4 strings to form the URI, seems dumb

to have 4
overloaded methods that take more and more strings ;)
So, what is causing this? This must have come up in the

past. I tried
searching google, but I'm not sure what terms to use to

describe the
problem.

If anyone has a solution (other than a function), I would

love to hear it.
Thanks.

-Steve
.

Nov 18 '05 #3
if you just use Default.aspx then it will take relative to
the current position. You can also store the path in the
web.config file and pull it from there..

BTW anchor tag == <a href>

-Shan
-----Original Message-----
It's not an Anchor Tag, it's a reg. <a href> tag, I need the runat cause I'musing the '~' to get to the VirtualRoot (dev server vs prod. server)

"Shan" <an*******@discussions.microsoft.com> wrote in messagenews:01****************************@phx.gbl...
Why do you need a runat tag for anchor tags? Since it is
inside the Datalist control,which has a runat tag I dont
think you need a runat tag for Anchor links.

Thanks,
-Shan
>-----Original Message-----
>hi-
>
>I have <a> tags in my DataList. For the href
property, I want to do
>something like this:
><a href='~/Default.aspx?show=Support&disp=Faq&p=<%#
>DataBinder.Eval(Container.DataItem, "name")%>'

runat=server>some link</a>
>
>Looks pretty straight forward, but when I add the

runat=server property it
>stops parsing the <% %> block correctly.
>
>The workaround has been to make a method that will
take 2 strings,
>concatentate them, then return the result, something
like this:
>public string BuildUri(string a, string b)
>{
> return a + b;
>}
>
>then in the <a> tag I do this:
><a href='<%#BuildUri("~/Default.aspx?

show=Support&disp=Faq&p=",
>DataBinder.Eval(Container.DataItem, "name"))%>'

runat=server>some link</a>
>
>
>That works. It's a pain though cuase a) I don't

understand why I need to do
>it in the first place and b) my needs have changed,

sometimes I will be
>combining 2,3 even 4 strings to form the URI, seems
dumb to have 4
>overloaded methods that take more and more strings ;)
>
>
>So, what is causing this? This must have come up in
the past. I tried
>searching google, but I'm not sure what terms to use to

describe the
>problem.
>
>If anyone has a solution (other than a function), I
would love to hear it.
>Thanks.
>
>-Steve
>
>
>.
>

.

Nov 18 '05 #4
you're right about anchor tag, I was confused with.... well, i dunno, but I
was ;)

problem with the relative thing is that I have nested controls(IE:
Navigation user control) that when nested using relative paths I get doulbe
up like:
Default.aspxDefault.aspx?show...

I remember I went through that a year ago... drove me nuts, then I
discovered the magic of the "~"....
"Shan" <an*******@discussions.microsoft.com> wrote in message
news:10*****************************@phx.gbl...
if you just use Default.aspx then it will take relative to
the current position. You can also store the path in the
web.config file and pull it from there..

BTW anchor tag == <a href>

-Shan
-----Original Message-----
It's not an Anchor Tag, it's a reg. <a href> tag, I need

the runat cause I'm
using the '~' to get to the VirtualRoot (dev server vs

prod. server)


"Shan" <an*******@discussions.microsoft.com> wrote in

message
news:01****************************@phx.gbl...
Why do you need a runat tag for anchor tags? Since it is
inside the Datalist control,which has a runat tag I dont
think you need a runat tag for Anchor links.

Thanks,
-Shan
>-----Original Message-----
>hi-
>
>I have <a> tags in my DataList. For the href property, I want to do
>something like this:
><a href='~/Default.aspx?show=Support&disp=Faq&p=<%#
>DataBinder.Eval(Container.DataItem, "name")%>'
runat=server>some link</a>
>
>Looks pretty straight forward, but when I add the
runat=server property it
>stops parsing the <% %> block correctly.
>
>The workaround has been to make a method that will take 2 strings,
>concatentate them, then return the result, something like this:
>public string BuildUri(string a, string b)
>{
> return a + b;
>}
>
>then in the <a> tag I do this:
><a href='<%#BuildUri("~/Default.aspx?
show=Support&disp=Faq&p=",
>DataBinder.Eval(Container.DataItem, "name"))%>'
runat=server>some link</a>
>
>
>That works. It's a pain though cuase a) I don't
understand why I need to do
>it in the first place and b) my needs have changed,
sometimes I will be
>combining 2,3 even 4 strings to form the URI, seems dumb to have 4
>overloaded methods that take more and more strings ;)
>
>
>So, what is causing this? This must have come up in the past. I tried
>searching google, but I'm not sure what terms to use to
describe the
>problem.
>
>If anyone has a solution (other than a function), I would love to hear it.
>Thanks.
>
>-Steve
>
>
>.
>

.

Nov 18 '05 #5
neverstill wrote:
hi-

I have <a> tags in my DataList. For the href property, I want to do
something like this:
<a href='~/Default.aspx?show=Support&disp=Faq&p=<%#
DataBinder.Eval(Container.DataItem, "name")%>' runat=server>some link</a>

Looks pretty straight forward, but when I add the runat=server property it
stops parsing the <% %> block correctly.

The workaround has been to make a method that will take 2 strings,
concatentate them, then return the result, something like this:
public string BuildUri(string a, string b)
{
return a + b;
}

then in the <a> tag I do this:
<a href='<%#BuildUri("~/Default.aspx?show=Support&disp=Faq&p=",
DataBinder.Eval(Container.DataItem, "name"))%>' runat=server>some link</a>
That works. It's a pain though cuase a) I don't understand why I need to do
it in the first place and b) my needs have changed, sometimes I will be
combining 2,3 even 4 strings to form the URI, seems dumb to have 4
overloaded methods that take more and more strings ;)

I can't help you with why there's a problem in the first place; however,
I can make a suggestion that might make your workaround a bit easier.

Instead of having your own BuildUri method that simply concatenates 2
strings with the prospect of having to create several overloads to deal
with varying numbers of string parameters, you can simply call the
String.Concat() static method - it already has a full set of overloads
to handle however many strings you want to serve up.

So, what is causing this? This must have come up in the past. I tried
searching google, but I'm not sure what terms to use to describe the
problem.

If anyone has a solution (other than a function), I would love to hear it.
Thanks.


--
mikeb
Nov 18 '05 #6
Hi Mike,

well that will save me some time for sure, but can I call string.Concat() in
a script block? I STILL don't understand what you can and can't do in the
*.aspx <%%> script blocks. I'll try it and see what happens.

Either way, thanks for the suggestion!

-SK

"mikeb" <ma************@mailnull.com> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...
neverstill wrote:
hi-

I have <a> tags in my DataList. For the href property, I want to do
something like this:
<a href='~/Default.aspx?show=Support&disp=Faq&p=<%#
DataBinder.Eval(Container.DataItem, "name")%>' runat=server>some link</a>
Looks pretty straight forward, but when I add the runat=server property it stops parsing the <% %> block correctly.

The workaround has been to make a method that will take 2 strings,
concatentate them, then return the result, something like this:
public string BuildUri(string a, string b)
{
return a + b;
}

then in the <a> tag I do this:
<a href='<%#BuildUri("~/Default.aspx?show=Support&disp=Faq&p=",
DataBinder.Eval(Container.DataItem, "name"))%>' runat=server>some link</a>

That works. It's a pain though cuase a) I don't understand why I need to do it in the first place and b) my needs have changed, sometimes I will be
combining 2,3 even 4 strings to form the URI, seems dumb to have 4
overloaded methods that take more and more strings ;)


I can't help you with why there's a problem in the first place; however,
I can make a suggestion that might make your workaround a bit easier.

Instead of having your own BuildUri method that simply concatenates 2
strings with the prospect of having to create several overloads to deal
with varying numbers of string parameters, you can simply call the
String.Concat() static method - it already has a full set of overloads
to handle however many strings you want to serve up.

So, what is causing this? This must have come up in the past. I tried
searching google, but I'm not sure what terms to use to describe the
problem.

If anyone has a solution (other than a function), I would love to hear it. Thanks.


--
mikeb

Nov 18 '05 #7
neverstill wrote:
Hi Mike,

well that will save me some time for sure, but can I call string.Concat() in
a script block? I STILL don't understand what you can and can't do in the
*.aspx <%%> script blocks. I'll try it and see what happens.

Either way, thanks for the suggestion!


You can use any .NET class from any assembly (yours, the Framework's or
a third party's) in an aspx script block provided:

1) the assembly is available at runtime (either by residing in the
bin folder or in the GAC), and

2) the assembly is referenced (either using an @Assembly directive
in the aspx file or an <add assembly ...> element in web.config)

Remember that the aspx file gets parsed into a C# or VB.NET file
(depending on the language specified in the @Page directive) which gets
compiled just like any other C# or VB.NET file. So if you call a method
in your script block that is not allowed because the assembly is not
referenced, you'll get a compilation error when you first access the page.

--
mikeb

Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: LRW | last post by:
OK, this is probably an odd, but esy question. =) I taught myself PHP from a Julie Meloni book and newsgroup questions. So, I don't think I've really learned the proper way of organizing and...
8
by: Jonathan | last post by:
Hi, I have to use the nl2br function in the asp file, luckly I got this code from a site. What I need done is to display textbox content the way it was typed/pasted i.e. with paragraph breaks and...
21
by: AnnMarie | last post by:
<script language="JavaScript" type="text/javascript"> <!-- function validate(theForm) { var validity = true; // assume valid if(frmComments.name.value=='' && validity == true) { alert('Your...
6
by: Ot | last post by:
I have an xml document similar to this <all> <one> <options attr1="1" attr2="2" /> <item name="a name" attr1="1" /> <item name="another" attr1="2"/> </one> <two> <options attr1="1"...
4
by: comp.lang.tcl | last post by:
I wrote this PHP function in the hopes that it would properly use a TCL proc I wrote about 4 years ago: if (!function_exists('proper_case')) { /** * Ths function will convert a string into a...
4
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the...
3
by: Patrick.O.Ige | last post by:
I have this Ajax script below that returns data ... var xmlHttp function showCustomer(str) { xmlHttp=GetXmlHttpObject();
1
by: Graham Hobbs | last post by:
Hello, My old laptop has DB2 V7 thereon. The only fixpaks I ever applied were FP1 (although I cant truly remember if I actually did this one) and FP2. Because it/they entirely satisfied my needs...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
30
by: Einstein30000 | last post by:
Hi, in one of my php-scripts is the following query (with an already open db-connection): $q = "INSERT INTO main (name, img, descr, from, size, format, cat, host, link, date) VALUES ('$name',...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.