Define function to change 'HR' length (C#) : Function « Language Basics « ASP.Net






Define function to change 'HR' length (C#)

<%@ Page Language="C#" Debug="true" %>
<script runat="server">

    void Page_Load()
    {
        if (IsPostBack)
        {
    
            lblMessage.Text = "First Line";
            InsertLinebreak(Convert.ToInt32(NumberOptions.SelectedItem.Value),
                            Convert.ToInt32(WidthOptions.SelectedItem.Value));
            lblMessage.Text += "Second Line";
            InsertLinebreak(Convert.ToInt32(NumberOptions.SelectedItem.Value),
                            Convert.ToInt32(WidthOptions.SelectedItem.Value));
        }
    }
    
    void InsertLinebreak(int NumLines, int Width)
    {
        for (int i=1; i<=NumLines; i++)
        {
           lblMessage.Text += "<br><hr width='" + Width.ToString() +
                              "' align='left'>";
        }
    }

</script>
<html>
<head>
    <title>Using Functions with Parameters</title>
</head>
<body>
    Choose the number and width of the linebreaks and then press submit 
    <form runat="server">
        <asp:RadioButtonList id="WidthOptions" runat="server">
            <asp:ListItem value="100">100 pixels wide</asp:ListItem>
            <asp:ListItem value="300">300 pixels wide</asp:ListItem>
            <asp:ListItem value="600">600 pixels wide</asp:ListItem>
        </asp:RadioButtonList>
        <asp:DropDownList id="NumberOptions" runat="server">
            <asp:ListItem value="1">1 Line</asp:ListItem>
            <asp:ListItem value="2">2 Lines</asp:ListItem>
            <asp:ListItem value="3">3 Lines</asp:ListItem>
        </asp:DropDownList>
        <asp:Button id="Button1" runat="server" text="Submit"></asp:Button>
        <br />
        <br />
        <asp:Label id="lblMessage" runat="server"></asp:Label>
    </form>
</body>
</html>

           
       








Related examples in the same category

1.Define and call function in a page (VB.net)
2.Page level procedure (VB.net)
3.Function Parameter passed by Reference (C#)
4.Function Parameter passed by Value (C#)
5.Using out Parameters (C#)
6.Simple function without parameters (C#)
7.Define and call function (C#)
8.Call function (C#)
9.Function local variable (C#)