My (mostly technical) blog

Data binding from a property in the code behind

Posted by: sabbour on: February 17, 2010

I’ve run across this situation multiple times, where I have for example, an ID that I get in the code behind, and I want to append it to some href in the aspx, and each time I forget how to do it, so as a reminder for myself, here is how to do it and problems I ran into:

Assuming I have a property in the code behind that returns a GUID

protected Guid CustomerId {
 get { return new Guid(); }
}

And assuming I have a link in my aspx page that I want to append this property to, here is how to do it

<a href="upgrade.aspx?id=<%= CustomerId .ToString() %>">Upgrade</a>

Note that this will not work if you specify a runat=server to the href for any reason, for example. to show the link or hide it according to specific logic.

If you need to show and hide the link, you can enclose it in a place holder and access that placeholder from the code behind

<asp:PlaceHolder ID="UpdgradeLinkPlaceholder" runat="server">
<a href="upgrade.aspx?id=<%= CustomerId .ToString() %>">Upgrade</a>
</asp:PlaceHolder>

Advertisement
Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Ahmed Sabbour's Facebook profile

 

February 2010
S M T W T F S
« Apr   Apr »
 123456
78910111213
14151617181920
21222324252627
28  

Tweets

RSS StackOverflow

  • Answer by sabbour for j2me: how to open application page via ovi store app February 22, 2012
    If the Nokia Store is installed, then opening the above URL in the browser will cause the Store client to open on the specified app.
  • Answer by sabbour for Horizontal listView inside Vertical Listview in qml February 22, 2012
    I tried this solution on the simulator and it worked. import QtQuick 1.1 import com.nokia.symbian 1.1 Page { id: mainPage anchors.fill: parent ListModel { id: colorsModel ListElement { colorCode: "red" } ListElement { colorCode: "green" } ListElement { colorCode: "blue" } ListElement { colorCode: "orange" } ListElement […]
  • Answer by sabbour for Push Notification for Nokia nid using c# February 20, 2012
    Please check the following project: https://projects.forum.nokia.com/dotnet_notifications_api It is a .NET wrapper for the Nokia Notifications API.
  • Answer by sabbour for Unable to compile Qt Symbian application that uses gSOAP September 13, 2010
    To finally make it work, I had to port gSOAP to use stdapis instead of libc. I removed one of the lines and used instead. You can find the ported stdsoap2.h file at http://pastebin.com/xnrDbfFa. I also discovered that Symbian does not load STL by default, so all my methods that were returning std::vector and std::string are now not compiling. Instead of opti […]
  • Unable to compile Qt Symbian application that uses gSOAP September 8, 2010
    I'm using gSOAP along with Qt for Symbian. Under the emulator, the application compiles fine, but when I change the target of the compiler to compile for the device, I get the following error. WARNING: Can't find following headers in System Include Path This gets included from the stdsoap2.h file as follows: #ifndef WITH_NOIO # ifndef WIN32 # ifnde […]

Recently bookmarked

Follow

Get every new post delivered to your Inbox.