Inline Expressions
-
I'm in the process of adapting an article, "Maintain Scroll Position in any Page Element" By Jim Ross, over at ASP Alliance. It's my first exposure to inline expressions, <%= %>. The code for my DIV tag where the scrolling takes place is:
DIV id=divAttributeType title="Attribute Type" style="Z-INDEX: 104; LEFT: 16px; BEHAVIOR: url(RetainScrollPosition.htc); OVERFLOW: auto; WIDTH: 936px; POSITION: absolute; TOP: 232px; HEIGHT: 200px" runat="server" ms_positioning="GridLayout" persistID="<%= hidDivAttributeTypeScrollPosition.id%>" scrollPos="<%= 5 %>"
persistID and scrollPos are properties defined in the HTML Component file referred to in the style's BEHAVIOR attribute. hidDivAttributeTypeScrollPosition is a hidden INPUT field. I set a breakpoint in one of the client-side scripts defined in the .htc file. When I look at the contents of these two "custom" properties, persistID and scrollPos, the contents are the literal values of the inline expressions i.e. "<%= hidDivAttributeTypeScrollPosition.id%>" and "<%= 5 %>" rather than the expected "hidDivAttributeTypeScrollPosition" and "5". When I hard code the name of the INPUT control the solution works wonderfully :-D but I've spent the last four hours trying to figure out why the inline expressions don't appear to be executed. Is there some switch the turns this sort of processing on and off. I'm stumped! X| Thanks, Will -
I'm in the process of adapting an article, "Maintain Scroll Position in any Page Element" By Jim Ross, over at ASP Alliance. It's my first exposure to inline expressions, <%= %>. The code for my DIV tag where the scrolling takes place is:
DIV id=divAttributeType title="Attribute Type" style="Z-INDEX: 104; LEFT: 16px; BEHAVIOR: url(RetainScrollPosition.htc); OVERFLOW: auto; WIDTH: 936px; POSITION: absolute; TOP: 232px; HEIGHT: 200px" runat="server" ms_positioning="GridLayout" persistID="<%= hidDivAttributeTypeScrollPosition.id%>" scrollPos="<%= 5 %>"
persistID and scrollPos are properties defined in the HTML Component file referred to in the style's BEHAVIOR attribute. hidDivAttributeTypeScrollPosition is a hidden INPUT field. I set a breakpoint in one of the client-side scripts defined in the .htc file. When I look at the contents of these two "custom" properties, persistID and scrollPos, the contents are the literal values of the inline expressions i.e. "<%= hidDivAttributeTypeScrollPosition.id%>" and "<%= 5 %>" rather than the expected "hidDivAttributeTypeScrollPosition" and "5". When I hard code the name of the INPUT control the solution works wonderfully :-D but I've spent the last four hours trying to figure out why the inline expressions don't appear to be executed. Is there some switch the turns this sort of processing on and off. I'm stumped! X| Thanks, WillHi there, Basically, you cannot use a code render block[^] (inline expressions, <%= %> ) to set a value for the property of an element with the
runat="server"
. In this case, there are a couple of ways to set the value: + Use an inline expression and comment out the stuff runat="server". + Add the runat="server", and use a data binding expression[^]<%# %>
, remember to call the Page.DataBind method so that the value of the expression can be populated and assigned to the property. + Add the runat="server", and assign a value to the property in the server side code: -
Hi there, Basically, you cannot use a code render block[^] (inline expressions, <%= %> ) to set a value for the property of an element with the
runat="server"
. In this case, there are a couple of ways to set the value: + Use an inline expression and comment out the stuff runat="server". + Add the runat="server", and use a data binding expression[^]<%# %>
, remember to call the Page.DataBind method so that the value of the expression can be populated and assigned to the property. + Add the runat="server", and assign a value to the property in the server side code:Ahhhhh, thanks SO much. I think at some point I was chasing a spelling error and added the runat="server" so that I could track it with Intellisense in the Code-Behind and then left it in there. Is there any chance that you could point me to somewhere that this is documented so that I can fully understand it rather than just incorporate it into my collection of dogma? Thanks again, Will
-
Ahhhhh, thanks SO much. I think at some point I was chasing a spelling error and added the runat="server" so that I could track it with Intellisense in the Code-Behind and then left it in there. Is there any chance that you could point me to somewhere that this is documented so that I can fully understand it rather than just incorporate it into my collection of dogma? Thanks again, Will
-
Been there and there, tried them (way before I asked believe it or not). There is WAY to much information in this environment that is not available without going spelunking. I've got a library of 17 books just on ADO.Net, ASP.Net, C#, the Framework, DHTML & Javascript. (At about $50 pop (list anyway) and all are about to be obsoleted by .Net 2.) Most of them seem to completely ignore a lot of the difficult and distasteful stuff. The Internet resources do a great job of sharing information and techniques but seldom point to any underlying documentation. The search for documentation combined with trial-and-error are HUGELY inefficient time-wise. Damn, I miss IBM software and documentation! I guess, as they say, "You guys get the big bucks". I think I'm going to post this on the "Rants" forum. Thanks again. Will