Feeds:
Posts
Comments

Auto Growing TextArea

Ehsan was telling me about the litte, simple and useful control.  All of us already seen that control in facebook chatting window. that textboox automatically bacome bigger according to the text written in the textbox.

Here is the demo of that JQuery http://www.aclevercookie.com/demos/autogrow_textarea.html

I have tested that in asp.net TextBox it works. Here is my code in asp.net for auto growing textbox.

You should download JQuery and JQuery Auto Grow to use it.

<script type=”text/javascript” src=”jquery-1.3.2.js”></script>
<script type=”text/javascript” src=”jquery.autogrow.js”></script>
<script type=”text/javascript”>
$(document).ready(function() {
$(‘.expanding’).autogrow();
});

<style type=”text/css”>
.expanding {line-height: 18px;}
</style>

<asp:TextBox ID=”myTxt” runat=”server” CssClass=”expanding” AutoPostBack=”false” TextMode=”MultiLine”></asp:TextBox>

Recently I developed a web application which calls many services and loads a lot of data in every page with a lot of calculation in the background from the database, so the site became slower. Then I start searching Google to find out a good solution and got some real good ideas to improve my web application’s performance. Here, in this article, I am shared the tips I applied in the application to improve performance and it really works fine now.

http://www.codeproject.com/KB/aspnet/aspnetPerformance.aspx

I needed to access every cell of a GridView in Client Side in one of my application, so needed to call javascript from GridView Cell. Actually I have a Dropdownlist , select any of the item from the dropdownlist will change the value of the same row in a different cell and will change the GridView footer row  value.

Here is a article showing how to access row and cell of a gridview from client site.
http://weblogs.asp.net/ashrafurrahaman/archive/2009/02/26/javascript-for-gridview-row-level.aspx

I needed to run my web application in a fixed port of my web server due to fixed SiteURL in the web site whcih I needed to change every time from the web config.

Here are simple and easy steps tp run your web application in a fixed port of your web server.

1. Go to Solution Explorer of your project
2. Go to properties of your web site clicking F4 on your web site name.
3. Make “Use Dynamic Port” to “False” and put a “Port Number“, you website will always run in that port number.

Send mail is an important and common feature in asp.net. using system.net.mail namespace  we can send mail. In that article my main concert is to show how shall we send mail asynchronously, as for a bulk of mail sending asynchronous mail send is very important and asp.net have that feature in it.

I had written a wiki in asp.net on with code on  send asynchronous mail.

here you will get codes do send  asynchronous mail http://wiki.asp.net/page.aspx/536/send-asynchronous-mail-using-aspnet/

I was reading httpwebresponse data and get the basic data from the html data. So i need to remove all html tag, script tags, style tags from page to get original text data. So use a simple regular expression to remove tags. this regular expression was simple like that.

Regex.Replace(mainData,@”<scripts[^>]*>.*?</script>|<s*(?!/?(?:br?|i|p|u)b[^>]*>)[^>]*>”,”", RegexOptions.IgnoreCase | RegexOptions.Singleline) ;

I was working fine but i found that for some pages these are making problem specially problems are coming to remove javascript and styles from html data and data was not coming in a good format.

Finally I have got a very nice tool to do that . name of the tool is Html Agility .

this is a very nice features in html agility , it has libraires to convert html to xml, html to rss and html to text. I used html to text yo convert my httpresponse data to text.

in html agility you will find a class HTMLDocument.cs If you want to convert your webresponses then just add these codes in Load method, bacuase in load method this is reading html file from a local drive so to read webresponse use that code.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), OptionDefaultStreamEncoding);

Caching is a very important concept in programming . caching is a very nice technique to speed up processing. To increase performance of application caching is a great enhance.

One of my buddy razwan has written a very nice article on asp.net caching using cache dependency on file. You can follow this article to implement that in your applicaiton to speed it up.

here is the link ASP.NET Caching with Cache Dependency on a File

Wrapping text

Sometime we face problen to wrap text. this is a very easy solution to solve wrapping problem .

public string GetFormattedText(string str)
{
string[] parts = str.Split(new char[] { ‘ ‘ });
StringBuilder sb = new StringBuilder();
foreach (string s in parts)
{
sb.Append(Server.HtmlEncode(s));
sb.Append(” <wbr>”);
}
return sb.ToString();
}

In case of firefox its is more easier, just use white-space: -moz-pre-wrap in css style.

i was reading a book head first design pattern, actually read that book many times, an excellent book. Sharing my details idea singleton design patter.

class diagram of Singleton design pattern

a singleton class is look like that
public class Singleton
{
private static Singleton UniqueInstance; //variable to hold one instance of the class Singleton
private Singleton(){}
public static Singleton getInstance()
{
if(UniqueInstance==null)UniqueInstance=new Singleton();
return UniqueInstance;
}
}
here the Singleton class constructor is private and it has only one static method to get it, that ensures that this class has only one instance, and provide a global point to access it.

Now think for multi threading…
what will happen??? suppose you have 2 threads, so 2 different instance of the object will be created.
WHATS THE SOLUTION ??? Continue Reading »

fun with Javascript

I faced a problem to call 2 methods at the same time from body. and the solution is very simple. I wrote a script block at the end of the page look like that.

<SCRIPT LANGUAGE=”JAVASCRIPT”>

if(document.body.onload)

{

var existingOnLoad = document.body.onload;

document.body.onload = function()

{

existingOnLoad();

MyOwnMethod();

}

}

</SCRIPT>

Older Posts »