Archive for the ‘ASPX Component’ Category

DataBinder.Eval function

I am creating a blog and I need to preserve white space for user comment. So I need to put <pre> tag around the comment content. In ASP.NET, I could do it in the ItemDataBound function and then use the FindControl function and append <pre> tags to the text property of the label. But there is a much better and easier way. Use the DataBinder.Eval function like below

<asp:Label ID=”CommentLabel” runat=”server” Text='<%# DataBinder.Eval(Container.DataItem,”comment_content”,”<pre>{0}</pre>”) %>’></asp:Label>

In my case, the “comment_content” is the name of the field in my table that contains the user htmlencoded content.


Using CSS Friendly Control Adapter to existing project

What it is:
Download and Install:

1. Downloading the current release. Go to the Releases tab. You should see three prominent links to files. The zip file contains the source code, the CSSFriendly.dll file contains the compiled source code, and the the CSSFriendlyAdapters.browser file is a configuration file. You only need the dll and browser files.
2. Add a reference to CSSFriendly.dll. This is typically done by right-clicking your web project, choosing the Add References command, browsing for the CSSFriendly.dll file, and clicking OK.
3. Add the CSSFriendlyAdapters.browser file to the AppBrowsers folder in the root of your web project. If the AppBrowsers folder doesn’t exist, create it.

You may notice the autoFormat you selected for your gridview or other controls is not working anymore. You will have to use the cssclass property of the control to specify the style you want.

Website display partially in IE 7

I am still using IE 6 at work and the website looks fine. When I get home, the website only display partial of the page.  It turns out that it only effect web pages with the Panel control on it. The problem is the default height for the Panel control is 50 px. IE 6 display the whole thing and IE 7 is more restrict and hence only display 50px of the panel. Solution is to get rid of the height.

the menu control in ASP.NET

To use sitemap file as the datasource for the the horizontal menu control,

  1. Put the SiteMapDataSource into the aspx page.
  2. Drag the menu control to the aspx page.
  3. Change its datasource to the SiteMapDataSource.
  4. Change the Orientation property of the menu to Horizontal.
  5. Change the StaticDisplayLevels property to 2, so that it will display the first 2 levels of the SiteMap. Default is one which is useless in my opinion if you are using a SiteMap file because it only shows the “Home” button or the first node in your SiteMap file.

Set the DefaultFocus or DefaultButton in a Page Based on a Master Page

When user type in the keyword in the search textbox and press the Enter key on keyboard, the webpage just do a simple postback. It doesn’t run the query until the user hit the “Search” button.

Use defaultfocus and defaultbutton.
defaultfocus puts the mouse cursor into the control when the page loads
defaultbutton cause the button click event, without it, it just cause a pagepost back

Because of the Master page, UniqueID and ClientID is necessary for this to work properly.

protected void Page_Load(object sender, EventArgs e)
Page.Form.DefaultButton = this.Button_Continue.UniqueID;
Page.Form.DefaultFocus = this.TextBox_PN.ClientID;

ASP.NET MultiView

Designer View:

<asp:Menu ID=”Menu1″ runat=”server” Orientation=”Horizontal” ForeColor=”#666666″>
<asp:MenuItem Text=”OPEN” Value=”0″ Selected=”True”></asp:MenuItem>
<asp:MenuItem Text=”ACCEPTED” Value=”1″></asp:MenuItem>
<asp:MenuItem Text=”REJECTED” Value=”2″></asp:MenuItem>

<asp:MultiView ID=”MultiView1″ runat=”server” ActiveViewIndex=”0″>
<asp:View ID=”View1″ runat=”server”>…</asp:View>
<asp:View ID=”View2″ runat=”server”>…</asp:View>
<asp:View ID=”View3″ runat=”server”>…</asp:View>

Code View:

Protected Sub Menu1_MenuItemClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles Menu1.MenuItemClick
MultiView1.ActiveViewIndex = Int32.Parse(e.Item.Value)
End Sub