How to pass variables to asp tags?

UncleRonin

Well-known member
Joined
Feb 28, 2006
Messages
230
Location
South Africa
Programming Experience
5-10
I've only just started using ASP.NET so I'm not clued up on all the syntax and stuff like that. What I'm trying to find out is if there is some way to pass an existing variable as a value in a server tag?

For example:
VB.NET:
Dim Refresh as Integer = 10
<asp:Timer Interval="<% Refresh %>" />

Is there some way to do this? Geh.
 
I am struggling with nearly the same problem. I want to pass string constant values to control properties.

I experimented with the approach that you proposed, but soon discovered that this is not valid, as control properties cannot be declaratively assigned values using the <%= %> syntax; you have to use the expression builder syntax, as follows:

<asp:Timer Interval="<%$ Values:Refresh %>" />

Note the $ sign, which indicates that what follows is an ASP.Net expression declaration.

Here's an MSDN article which includes some description of expression builders and describes how to build a custom expression builder to return any type of value.

http://msdn.microsoft.com/msdnmag/issues/05/02/WickedCode/

I followed their example and it worked perfectly, but I'm still stuck. In order to pass a constant or variable value into a control property using an expression builder, you need to be able to access that value, given only its name, at runtime.

I can't find anything in the .Net Frameork that will return a constant or variable value by name. It seems that the Microsoft.VisualBasic.Interaction.CallByName() method might almost do the trick, but I can't work it out.

Does anyone else have any ideas how to do this?

Thanks

Tim
 
Back
Top