Saturday, October 02, 2010

How to write some html to asp.net page output stream

<%@ Page Language="C#" %>
<html>
<head id="Head2" runat="server">
    <script runat="server">
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            ///
            /// Method 1:
            ///
            string htmlInput = "<input type=\"text\" id=\"inputId\" name=\"inputName\" value=\"Hello World\" />";                        
            this.phHtmlControl.Controls.Add(new Literal() { Text = htmlInput });
            ///
            /// Method 2:
            ///
            this.phHtmlControl.Controls.Add(
                ParseControl("<asp:CheckBox ID=\"chkDisabled\" Text=\"Disabled\" runat=\"server\" />"));            
        }
        protected void Save(object sender, EventArgs e)
        {
            ///
            /// Method 1
            ///
            string htmlInputValue = this.Request.Form.Get("inputName");
            ///
            /// Method 2
            ///
            CheckBox chkDisabled = (CheckBox)FindControl("chkDisabled");
            if (chkDisabled != null)
                bool disabled = chkDisabled.Checked;
        }
    </script>
</head>
<body>
    <form id="form2" runat="server">
        <asp:PlaceHolder runat="server" ID="phHtmlControl" />
        <asp:Button runat="server" ID="btnSave" Text="Save" OnClick="Save" />
    </form>
</body>
</html

1 comment:

Joshua Smith said...

Thank you for sharing with useful, good tips. Currently mobile technologies are the most used in android phone development that needs in developing of mobile software applets for cells.

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...