In my Form.aspx page, I have the following line in Page_Load:
userName = HttpContext.Current.Request.LogonUserIdentity.Name.Split('\\')[1];
And I am using the following line to set some text on the form itself:
userLabelSecret.Text = $"Hello {userName}. Please enter a secret word or phrase:";
I would like to do something like this in the form instead:
<asp:Label ID="userLabelSecret" runat="server" Text="Hello <%=userName%>. Please enter a secret word or phrase: "></asp:Label>
However, this just shows the string <%=userName%> rather than the actual userName variable.
Is it possible to embed the variable in the Text attribute like this, instead of assigning it in Page_Load?
I tried doing this will the normal C# concatenation operator (+) but this causes the following error:
<asp:Label ID="userLabelSecret" runat="server" Text= "Hello " + <%=userName%> + ". Please enter a secret word or phrase: "></asp:Label>
The name 'userLabelSecret' does not exist in the current context
userSecretLabeltouserLabelSecret? Refactor both designer and code behind .cs file to match Label ID in aspx page if you don't sure.userLabelSecret