Category Archives: ASP.NET 2.0

Changing Page Title and Meta Tags with Master Pages

Master Pages are good for so many things. They also cause some confusion on how to have a different page title for each page, how to specify Meta Tags, etc.

This post is neither on Master Pages nor on best practices on handling these two topics. I would try to list couple of simple ways to handle them.

Title:

Title tag in Master Page acts as a place holder. On each page that uses Master Page, specify the “Title” in the page declarative.

In your content page, i.e., (.aspx),

<%@ Page Language=”C#” MasterPageFile=”~/Master1.master” AutoEventWireup=”true” Title=”Content Page Title” %>

You could also change the “title” tag in the code file as follows.

base.Master.Page.Header.Title = “Content Page Title”;

Meta Tags:

Meta Tags are little different compared to setting the page Title. Check the code that creates a meta tag “keywords” with content “ASP.NET, AJAX, Web Services”.

HtmlMeta metaTag = new HtmlMeta();

metaTag.Name = “keywords”;

metaTag.Content = “ASP.NET, AJAX, Web Services”;

base.Master.Page.Header.Controls.Add(metaTag);

If you need to do this in multiple content pages, you might want to have a base page with properties like, “MetaKeywords”, “MetaDescription”, “MetaRobots” etc. So, on your regular page you could set these properties.

ASP.NET Url Re-writing and Postback Problem Solution

If you are doing any web-applications, chances are you have heard of Search Engine Optimization, also know as SEO. Its all about getting better search engine ranking for your web-pages.

Even though, there are no fixed rules on what to do, there is a general consensus among web masters, on what helps your search engine rankings. And one of them is having a better URL, in other words, having the key words in your URL using URL Re-writing.

The problem with ASP.NET is that once you do URL rewrite, all your post back would stop working. This has been a dis-advantage when it comes to SEO of your pages. There were few tricks we could have done to have it work, but, they are more of a hack than pretty solutions. I have linked to one of those solutions here a while ago.

But, Now with the advent of CSS control adapters, it is not only very easy to URL rewrite and have the postbacks work but also clean [hack!].

Here is a very nice article on various options on URL rewitting from ScottGu’s Blog

All the solutions offered are very clean and i happen to use the CSS control adapter solution on couple of my sandbox projects,

1) An online classified site for my home state, Andhra Pradesh

2) Online Deal and Coupon Aggregation site

-Cheers,

AJAX Usability Question when the screen is being updated

 

I am working on a simple web application that aggregates RSS from different Online Deal Site in to one place. One of the things I wanted to do was to have one page and load the RSS details in to an Update Panel. I know Update Panel is not the best when it comes to performance but it does its job and with proper caching on the server side, it is very good for my purpose. And more over this blog is not about the merits and/or de-merits of UpdatePanel but on Usability from an end user perspective.

I was using “UpdateProgress” from AJAX control tool kit and it is working very well with simple “update message” while the update panel is being processed. But, there are times when there is not any delay and the “Progress Bar” is not coming up. This may not be the desirable condition as user might not recognize that the screen has new information.

So, I needed some thing more to say that the screen has been updated. I looked in to “UpdatePanelAnimationExtender” to work with the condition. This Extender supports Animations while the screen is being updated and after the update.

 

<cc1:UpdatePanelAnimationExtender ID=”UpdatePanelAnimationExtender1″ runat=”server” EnableViewState=”false” TargetControlID=”UpdatePanel1″>
<Animations>
<OnUpdated>
<Sequence>
<EnableAction Enabled=”true” />
<Color AnimationTarget=”UpdatePanel1″
Duration=”.5″
z-index=”5″
StartValue=”#FFCC99″
EndValue=”#FFFFFF”
Property=”style”
PropertyKey=”backgroundColor” />
</Sequence>
</OnUpdated>
</Animations>
</cc1:UpdatePanelAnimationExtender>

In addition to this I could have another animation to show while the target update panel is being updated with entry like

<OnUpdating>

</OnUpdating>

But I am not sure if this would inform the intended message to the end user! So I have decided to go in-between route. Show the “Progress Bar” while the update panel is being updated and show a simple color transition when the panel is being updated.

To outline the code is looks something like this

<asp:UpdatePanel id=”UpdatePanel1″>

<ContentTemplate>

<asp:UpdateProgress ID=”UpdateProgress1″ runat=”server”>
<ProgressTemplate>
<div class=”ProgressClass”>
Please Wait While the Page is Loading…
</div>
</ProgressTemplate>
</asp:UpdateProgress>

<asp:GridView>

</asp:GridView>

</ContentTemplate>

</asp:UpdatePanel>

<cc1:UpdatePanelAnimationExtender TargetControlID=”UpdatePanel1″>

</cc1:UpdatePanelAnimationExtender>

You could find more about these controls here

-Thanks,

Error: "Sys" is Undefined error

I was playing with AJAX enabled applications for some time but not really done any thing major yet. I was working on a small project that required me to add some AJAX functionality using simple updatepanels. I dropped the necessary controls like scriptmanager and updatepanel in to the page and added the references to System.Web.Extensions.

I ran the application and ran in the error message mentioned above.

Error: “Sys” is Undefined Error

I read some blogs and added another reference to “System.Web.Extensions.Design” and added some

<handler> tags to the web.config file.

Nothing seemed to work and I still had the issue.

I got smart at this time and created a new AJAX enabled web site in Visual Studio and copied the web.config file over to my existing application.

The error message is gone!!!

XmlDataSource databinding xML file to data-bound controls like DataView and DataList

I have pulled in few resources on couple of ways we could databind an XML file to a Data-Bound controls using XmlDataSource.

Basically the idea is to be able to bind an XML file, either a physical XML file or XML formatted String using XMLDataSource.

1) This article from MSDN talks about how to bind an external (physical) XML file to a TreeView Control. These Concepts are same for all the other data-boundable controls like DataView, DataList, etc

http://msdn2.microsoft.com/en-us/library/494y92bs(vs.90).aspx

You can see how you could simply bind the XML file, Transform it before binding, and using XPath to filter further.

One thing I think its missing is reading/binding values form an XML node attribute value.

Taking further the examples mentioned in the above article, assuming you have an XML attribute, “ID” for Person node, in the databinding columns you could read/bind it as

<asp:TreeNodeBinding DataMember=”Person” TextField=”ID” />

You are specifying the name of the attribute for “TextField” instead of the “#InnerText” that read the InnerText of the Node.

2) We could also bind an inline XML string using XmlDataSource as discussed in this article from another MSDN article

http://msdn2.microsoft.com/en-us/library/ms228250(vs.80).aspx

-Hope it helps…

An Introduction to JSON in JavaScript and .NET

I found this An Introduction to JavaScript Object Notation (JSON) in JavaScript and .NET article to be very useful especially if you are new to JavaScript Object Notation (JSON)

Explore some of the Object Oriented Techniques of JavaScript, check this MSDN article, http://msdn.microsoft.com/msdnmag/issues/07/05/JavaScript/default.aspx, by Ray Djajadinata (Ray Hsieh).

Happy Scripting!!!

PostBacks does not work with Url Rewriting

I use a Url Rewriting a lot and ran into this problem very offen. There are multiple solutions to this issue and basically we would be manipulating the “post” action of the web page.

Here is a link that talks about a more elegent approch to solove this problem, Postbacks does not work with URL ReWriting.

http://weblogs.asp.net/jezell/archive/2004/03/15/90045.aspx

EDIT: please see my new entry on this topic http://blog.budigelli.com/index.php/2007/06/14/aspnet-url-re-writing-and-postback-problem-solution/

– Thanks,