accessing a code-behind variable from a user control

  • Thread starter Thread starter TB
  • Start date Start date
T

TB

On a user control (ascx) I have a datagrid with a hyperlink column
containing the following code:

<asp:HyperLinkcolumn headerstyle-width="80px" ItemStyle-Width="80px"
DataNavigateUrlField="ID" DataNavigateUrlFormatString="home.aspx?
i={0}&amp;<%=lang%>"
Text="Click"></asp:HyperLinkcolumn>

However when I run the page containing the user control, the resulting
link in the column litterally contains ";<%=lang%>" and not the lang
variable that I want to call.

What I am doing wrong here?

Thanks

TB
 
In one of my pages I construct the NavigateUrlFormatString during page Load
event where I insert the variable value into the link format.

Not sure whether you can achieve it using declarative syntax ...
 
I could do the whole datagrid programmatically, but in this case I
prefer it the "old way".

Could the problem be caused by an accidental combination of characters
(double quotation marks, etc), which could avoided by way of using
HTML equivalents (&quot;, &amp;, etc)?

TB
 
Not sure whether this is any cleaner, but another way could be to add one
more column to the grid's datasource which value would be set to your code
behind variable (you can even vary it from row to row) and then inside the
grid's column:

DataNavigateUrlFields="MyIdFieldName,MyCodeBehindCalculatedFieldName"
DataNavigateUrlFormatString="home.aspx?i={0}&{1}"
 
Back
Top