Skip to content

Tip – How to output a literal string that contains a HTML control

January 28, 2013

Last Thursday, I experimented if a literal string on a ASP.NET page can contrain a HTML control which in my case is a checkbox which can do a page postback, as essentially its just javascript that does this. In fact you can do this: –

If you store you output string for the ASP Literal string as something like: –

string output = @”<tr><td id=’id1′ runat=’server’>Remove User</td><td id=’id2′ runat=’server’>&nbsp;</td><th id=’id3′ runat=’server’><input id=’chkboxRemoveUser’ type=’checkbox’ runat=’server’ checked=’checked’ onclick=””javascript:setTimeout(‘__doPostBack(\’chkboxRemoveUser\’,\’\’)’, 0)””></th></tr>”;

in to the ASP.NET literal control in text.

Once you run the page, and click the checkbox it actually does a page postback after observing the source code for an ASP.NET checkbox.

Why would you do this? This is useful if you would like to do output this control based on user permissions without having the overheard of having a placeholder for a ASP.NET checkbox on the page, you can simply output as a literal string.

Only flipside is you have to do checks like the following code to check if the checkbox is checked: –

                if (LiteralLabel.Text != “”)
                {
                    if (!LiteralLabel.Text.Contains(“checked”))
                    {

                        // do something

                     }

                }

 

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: