ASP.NET 4.0 Hosting & ASP.NET 4.5 Hosting BLOG

BLOG about ASP.NET 4.5 Hosting, ASP.NET 4.0 Hosting and .NET 4.5 Framework and its Capabilities

ASP.NET 4 Hosting :: Html Encoded Expressions in ASP.NET 4.0

clock November 17, 2011 06:09 by author darwin

Introduction

We all know <%=expression%> features in asp.net. We can print any string on page from there. Mostly we are using them in asp.net mvc. Now we have one new features with asp.net 4.0 that we have HTML Encoded Expressions and this prevent Cross scripting attack as we are html encoding them.

ASP.NET 4.0 introduces a new expression syntax <%: expression %> which automatically convert string into html encoded. Let’s take an example for that.
I have just created an hello word protected method which will return a simple string which contains characters that needed to be HTML Encoded. Below is code for that.


protected static string HelloWorld()
{
   return "Hello World!!! returns from function()!!!>>>>>>>>>>>>>>>>>";
}

Now let’s use the that hello world in our page html like below. I am going to use both expression to give you exact difference.

<form id="form1" runat="server">
<div>
   <strong><%: HelloWorld()%></strong>
</div>
<div>
   <strong><%= HelloWorld()%></strong>
</div>
</form>

Now let’s run the application and you can see in browser both look similar. 



But when look into page source html in browser like below you can clearly see one is HTML Encoded and another one is not.



Cool, right?? Happy Programming.



ASP.NET Hosting :: How to Display Images with ASP.NET CheckBoxList Control

clock November 3, 2011 06:49 by author darwin

In this tips I will discuss how you can customize the rendering of ASP.NET CheckBoxList control with images.  Let’s consider a scenarios where you want to show some status images with every checkbox with in a CheckBoxList. Many developers use table with checkbox and images in different cell to display Images with checkbox.  But, we can easily achieve the same using CheckBoxList control itself.

Let’s  consider you have items in a CheckBoxList control.



If you run your web application with above CheckBoxList items, you will get below output



Now you want images instead of the text with the list of checkbox controls. If you look in to the code, as of now, nothing has been written with in NewCheckList_DataBound method.  To enable the adding icon  we have to override the content of items which is being  generating during  data bound. Below is a simple code which will enable to add  icons for every CheckBo  item in the CheckBoxList



What we did is just iterating through each element and override the  item text as per our requirement . Once run, you will get the output as below.



If you want avoid the text, you just need change the override content of item.Text.



So not only the icon, you can add any HTML Content as per requirement.



ASP.NET 4.0 & ASP.NET 4.5 Hosting

 

ASPHostCentral is a premier web hosting company where you will find low cost and reliable web hosting. We have supported the latest ASP.NET 4.5 hosting and ASP.NET MVC 4 hosting. We have supported the latest SQL Server 2012 Hosting and Windows Server 2012 Hosting too!

 

Calendar

<<  November 2024  >>
MoTuWeThFrSaSu
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

View posts in large calendar

Sign in