By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,760 Members | 1,644 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,760 IT Pros & Developers. It's quick & easy.

problem formatting URL in script

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.