Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Inline statement is not interpreted correctly

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Froefel - 12 Jul 2007 12:33 GMT
Hi all,

I have a curious thing that I can't figure out.

I have an aspx page with associated code-behind file; the aspx page
has the following code:

    <asp:LinkButton ID="lnkShowMyProjects" runat="server" PostBackUrl="~/
SelectProject.aspx?show=<%= User.Identity.Name %>">Show only my
projects</asp:LinkButton>

When I run this project and I look at the Page Source after the page
has been rendered, the above statement was translated into:

    <a id="ctl00_pageContent_lnkShowAllProjects"
href="javascript:WebForm_DoPostBackWithOptions(new
WebForm_PostBackOptions(&quot;ctl00$pageContent
$lnkShowAllProjects&quot;, &quot;&quot;, false, &quot;&quot;,
&quot;SelectProject.aspx?show=&quot;, false, true))">Show all
projects</a>

As you can see, instead of replacing <%= User.Identity.Name %> with
the actual value of User.Identity.Name, it included the statement as a
literal string. Consequently, the Querystring doesn't look the way I
intended it.

Can anyone tell me what the reason is for this behavior? Also can you
tell me how I should fix it?

Thanks
-- Hans
Patrice - 12 Jul 2007 15:03 GMT
The <% notation inside attributes is AFAIK only available to replace the
full attribute i.e. you could do :
PostBackUrl='<%="SelectProject.aspx?show="  & User.Identity.Name %>'

You may still want to check as I prefer to do such thing in codebehind and
doesn't work much perhaps even never more with "inlined" code...

If you still want to go this route you could use a compromise such as
(clearer IMO) :
PostBackUrl='<%=ProjectSelectionUrl%>' with ProjectSelectionUrl as a
function that returns the correct string.

As a side note, passing the user name in the query string is generally not a
good idea (if on the same server why to let this go client side at all where
it could be changed ?)

---
Patrice

> Hi all,
>
[quoted text clipped - 27 lines]
> Thanks
> -- Hans
bruce barker - 12 Jul 2007 16:35 GMT
there are 3 more requiments.

1) you can only use a binding expression (<%# expression %>), not a
response.write (<%= expression%>).

2) the control must support the method DataBind() or be nested inside a
control that supports databinding its children.

3) you must call DataBind() on the control.

-- bruce (sqlwork.com)

> The <% notation inside attributes is AFAIK only available to replace the
> full attribute i.e. you could do :
[quoted text clipped - 46 lines]
>> Thanks
>> -- Hans
GroupReader - 12 Jul 2007 17:44 GMT
I think you can't use the <%= xxx %> syntax with a "runat=server"
webcontrol.  It only works when replacing text in an html control
(without runat=server).

Is that correct?

.. and as Bruce mentioned, you can use databinding with the data-
centric webcontrols with this syntax: <%# xxx  %>
GroupReader - 12 Jul 2007 17:45 GMT
In your code-behind, you can put lnkShowMyProjects.PostBackUrl =
"xxxx";
Froefel - 12 Jul 2007 23:23 GMT
Thanks to everyone for their input...
Eventually I found the same solution as what GroupReader suggested,
and indeed what Patrice was saying made sense (allthough I didn't try
it).

Thanks again for the insights.

-- Hans

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.