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.

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...