Data Binding ASP.Net Tutorial


protected void Page_Load(object o, EventArgs e) {
    if(IsPostBack) {
        Page.DataBind();
    }
}
protected double CalculateFactorial(int input) {
    double result = 1;
    for(;input > 0; input--) {
        result *= input;
    }
    return result;
}


Databind the result of a method call.

    runat="server"
    ControlToValidate="theInput"
    ErrorMessage="input is required" />
    runat="server"
    ControlToValidate="theInput"
    ErrorMessage="input must be >= 0 and < 20"
    Type="integer"
    MinimumValue="0"
    MaximumValue="20" />
    runat="server" 
    type="submit" 
    Text="Calculate Factorial" />
The result is: <%# CalculateFactorial(Int32.Parse(theInput.Text)).ToString() %>