I'm trying to pass a variable into my "asp:Button CommandArgument" - I know that I've got to jump through some hoops as runat=server is set, but I have tried everything I have found so far, but to no avail
I know that my code behind works nicely as, if I explicitly define the variables in my "asp:Button CommandArgument" everything works - but as soon as I try to insert a variable via <% %> syntax? The variable is NOT replaced by the string it represents
I'm using vStudio 2019 community preview (and 2017) as my IDE, targeting .net framework 4.7.2 - everything builds cleanly, and I know that the value for the variable is being set - it's jut not making it into my "asp:Button CommandArgument" and I need it to
I've tried everything I have found - all permutations of the <% $> syntax I can find, tried using CodeExpressionBuilder
The pertinent part of my problematic code is
<% if (variable is "value") { %>
<asp:Button ID = "button1"
runat = "server"
Text = "Processing '<%: variable %>' Records"
CommandArgument = '<%: variable %>'
OnCommand = "button1_Click"
/>
<% } %>
I expect the variable I am inserting into the "asp:Button CommandArgument" to be replaced by it's current value
What I get? Various error messages and the literal translation of my ' or " wrapped <%: <%# <%= variable %> which doesn't help
I know I can hard-code some of what I want to accomplish - but that's not optimal, and doesn't help me when I want to pass variable dates to my procedures via "asp:Button CommandArgument"
I know I must be doing something wrong - but cannot, for the life of me, figure out what
Any suggestions?
CommandArgumentpart is using single quotes around what would be the value. Should those be double quotes like the other attributes? Does theTextattribute get the correct value? And where/how is "variable" defined? Perhaps it's a scope issue?