Code blocks are not supported in this context

Hi,

I am trying to have this in my user control But I am getting error saying code blocks are not supported in this context.

In my user control I am just putting <% if request.querystring("test")="tom" then %>
<asp:textbox id=txt1 />
<%end if%>
sureshrainaAsked:
Who is Participating?
 
bsdotnetConnect With a Mentor Commented:
Either
<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Request("test") = "tom" Then
            Dim a As New TextBox
            a.ID = "txt1"
            Me.form1.Controls.Add(a)
        End If
    End Sub
</script>

OR

<body>
    <form id="form1" runat="server">
    <div>
       <% If Request("test") = "tom" Then%>
        <asp:TextBox id=txt1 runat=server />
        <%  End If%>
        </div>
    </form>
</body>
0
 
deepaknetCommented:
Rather than this you can do like

<asp:textbox id="txt1" runat="server">

In the codeBehind Page_Load:

if (Request.QueryString("test")  == "tom") then
    txt1.Visible = true
else
   txt1.Visible = false
end if
0
 
deepaknetCommented:
Correction

Replace == with = in the snippet I have given you. (a bit of C# flavor!)
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
bsdotnetCommented:
Try this, it should work,
        <% If Request("test") = "tom" Then%>
        <asp:TextBox id=txt1 runat=server />
        <%  End If%>
0
 
RamuncikasCommented:
<%= if request.querystring("test")="tom" then %>
0
 
RamuncikasCommented:
Oops...won't work.....sorry
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.