get value from server code

sdlangers

Well-known member
Joined
Dec 3, 2002
Messages
118
Hi,

I need a way of doing this in asp.net

<input type=hidden name="amount" value="<%=amount%>">

where amount is on the server codebehind.

this was the way to do it in the old asp, but now, even if i declare the variable amount in the pageload event, it still gives me an error saying it is undeclared.

the <input> tag is part of a form and cant be made to runat server side

thanks for your help

danny.
 
Three other ways of doing the same thing:

Code:
<script runat="server">

    Dim amount As Integer

    Sub Page_Load(sender As Object, e As EventArgs)
        amount = 10
        ctlAmount.Value = amount.ToString()
    End Sub

</script>

<html>
    <head>
        <title></title>
    </head>
    <body>
        <form>
            <input id="ctlAmount" type="hidden" name="amount" value="" runat="server" />
        </form>
    </body>
</html>

Code:
ctlAmount.Attributes("value") = amount.ToString()

Code:
<script runat="server">

    Dim amount As Integer

    Sub Page_Load(sender As Object, e As EventArgs)
        amount = 10
    End Sub

</script>

<html>
    <head>
        <title></title>
    </head>
    <body>
        <form>
            <input type="hidden" name="amount" value="<%=amount.ToString()%>" />
        </form>
    </body>
</html>
 
Back
Top