September 29, 2008
Preloading means loading an object (graphics, text, movie) before showing it to output.
A good example is of preloading in flash files, when you see a loader before displaying the content, and after loading site shows a smooth experience of flow of data.
This is mostly used when there is an mouser over images to be loaded. If user mouse overs an image and then you loads the new mouse-over image it may take a few seconds to load, which leads to a small blank image over the image area. By pre-loading the image you can show mouseover image instantly without any delay.
In this post I am explaining how to do preaload imags in HTML using JavaScript, without using flash.
We have to use the Head tag of html as this is the one which loads on first page executiution.
<head>
<script type=”text/JavaScript”>
if (document.images)
{
pic1= new Image(190,53);
pic1.src=”images/productSmall.gif”;
pic2= new Image(190,53);
pic2.src=”images/storeSmall.gif”;
}
</script>
</head>
The above code lods two images naming productSmall.gif and storeSmall.gif respictively from images directory. It creates a new object of image and assigns it a dimention and a file to load.
The document.imags condition has been used to determine that the browser supports the images or not.
Leave a Comment » |
Html, JavaScript | Tagged: Html, JavaScript |
Permalink
Posted by dotnetcoderoom
September 29, 2008
You may have used RequiredFieldValidator with Text controls, but if you wnat to use it with DropDownList controls, you need to do some little extra work. Here is the trick.
Step 1: Create an DropDownList
Step 2: Drag and RequiredFieldValidator. Set it’s ControlToValidate property to the DropDownLis’s object.
Step 3: Fill some items in the DropDownList. Add a first item as “Select”. This will indicate the user that he should select an option.
Step 4: Now set the RequiredFieldValidator’s “InitialValue” property to “Select”.
Now all of your code should look like this :
<asp:DropDownList ID=”cmbCountry” runat=”server”>
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>India</asp:ListItem>
<asp:ListItem>USA</asp:ListItem>
<asp:ListItem>Canada</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID=”rqCountry” runat=”server” ErrorMessage=”*” SetFocusOnError=”True” ControlToValidate=”cmbCountry” InitialValue=”Select”></asp:RequiredFieldValidator>
Now you are all set to go and test it.
To read complete post and source code please visit dotnetcoderoom.blogspot.com
1 Comment |
Asp.Net | Tagged: Asp.Net, Asp.Net Controls, Validation Controls |
Permalink
Posted by dotnetcoderoom
September 24, 2008
If you want to change the MS Sql 2005 ’s password then just run the following sql query after logging into query anlyzer
sp_password ‘oldPassword’ , newPassword’
Note
Always use strong SQL passwords (i.e. having uppercase characters , lowercase characters, numeric values, special characters) for security purpose, this way it will be difficult to hack, hard to guess, hard to crack by brute force attacks.
Leave a Comment » |
DataBase, MS SQL | Tagged: DataBase, MS SQL |
Permalink
Posted by dotnetcoderoom
September 17, 2008
To show line breakes in a server side asp.net label, you can either use a HTML formatted text or a plain text.
HTML formatted text contains “<br>” tags so while rendring the control .net framework handles the task to show the proper html formatted text into a Label.
Example:
lblDescription.Text=”name <br>description”;
The above code will display a line gap between name and description.
But in case if user inputted data using a non-html enabled textbox then it is a point of problem.
While displaying data, inputted by simple multiline textbox, line breaks looses its state and when the data displayed on a label it looks like a simple constant text line. Interestingly if you try to show the same data back in a textbox it will look nice with proper line breaks. But we can’t use textbox every where because of designing requirements.
To keep the line breaks you must convert the html new line special indicator to HTML break “<br>” tag.
Solution:
lblDescription.Text = txtInput.Text.ToString().Replace(Environment.NewLine, “<br />”);
The above code replaces the “NewLine” indications to “<br>” at run time, and displays the data same as input formatting.
For demo source code visit
http://dotnetcoderoom.blogspot.com/2008/09/show-line-breakes-in-aspnet-label.html
1 Comment |
Asp.Net, Asp.Net Label, Asp.net Textbox, Html | Tagged: Asp.Net, Asp.Net Label, Asp.net Textbox |
Permalink
Posted by dotnetcoderoom
September 8, 2008
Cause
This error comes up when you tries to append two strings with the “+” sign. As the + sign in C# is a arithmetical operator so you cannot use this too append two string type values. To use “+” the values or variables must be if numeric type.
As C# uses doesn’t supports implicit typecasting, for string concatenation use “&” sign.
Example
string varTest = “”;
string str1 = “abc”;
int str2=21;
varTest = str1 + str2;
The above stqatmet will cause in error stating “Operator + cannot be applied to operands of type string and method group“. Because we are trying to add a string variable in a numeric variable.
To remove the error you must convert all the numeric (integer) datatype or variables to string.
varTest = str1 & str2.ToString();
The output of the above code will be abc21
Conclusion
We must convert all values to a uniform datatype before storing them into a variable.
2 Comments |
C# | Tagged: C#, Datatype Handling |
Permalink
Posted by dotnetcoderoom
September 6, 2008
The following code example can be used to send email using Asp.Net in 2.0 and higher versions version.
The Namespace of email class is changed to System.Net.Mail from System.Web.Mail.
Import the System.Net.Mail Namespace
using System.Net.Mail;
Code:
MailMessage mail = new MailMessage();
mail.From = new MailAddress(“info@yourDomain.com”,”Alert”);
mail.To.Add(“you@yourdomain.com”);
mail.Subject = “mail test”;
mail.IsBodyHtml = true;
mail.Body = “Your message here”;
SmtpClient smtp = new SmtpClient(“mail.yourdomain.com”);
smtp.Credentials = new System.Net.NetworkCredential(“info@yourdomain.com”,”password of this info”);
smtp.Send(mail);
Note:
The email address specified in the “FROM” field must be valid and it need to be of your domain.
In the SmtpServer the domain name must be same as of your domain on which website is hosted.
For complete source code visit
http://dotnetcoderoom.blogspot.com
Leave a Comment » |
Asp.Net, C# | Tagged: Asp.Net, C#, Send Email using asp.net 2.0 |
Permalink
Posted by dotnetcoderoom
September 6, 2008
The following code example can be used to send email using Asp.Net in 1.1 version.
First import Web.Mail namespace.
using System.Web.Mail;
Now add this code to your button click event:
MailMessage mail = new MailMessage();
String msgText = string.Empty;
msgText = “Message here, you can also use Html tags for Rich Text Formatting.<br>Hi.”;
mail.To = “you@yourdomain.com”;
mail.CC = “anyEmailAddress, its optional”;
mail.Bcc = “anyEmailAddress, its optional”;
mail.From = @”"”Ajay”" <info@yourdomain.com>”;
//mail.From = “info@yourdomain.com”;
mail.Subject = “Mail test”;
mail.BodyFormat = MailFormat.Html;
mail.Body = msgText;
SmtpMail.SmtpServer = “mail.yourdomain.com”;
SmtpMail.Send(mail);
Note:
The email address specified in the “FROM” field must be valid and it need to be of your domain.
In the SmtpServer the domain name must be same as of your domain on which website is hosted.
Leave a Comment » |
Asp.Net, C# | Tagged: Asp.Net, C#, Send e-mail in Asp.net |
Permalink
Posted by dotnetcoderoom
September 4, 2008
Yapee.
Google has launched it’s own web browser named Google Chrome.
Google Chrome is a very simple and sophisticated browser and very easy yo use.
Google Chrome Features:
~ Multiple tabs can be opened in same instance window.
~ Thumbnails of most visited pages.
~ Automatic bookmarks and history search reaults when you type any URL.
~ Import settings and bookmarks from other web browsers.
~ Application shortcuts
~ Dynamic tabs
~ Crash control
~ Incognito mode
~ Safe browsing
~ Instant bookmarks
~ Simpler downloads
For more features visit http://www.google.com/chrome/intl/en-GB/features.html
So go and give a try to Google Chrome.
Download Google Chrome here http://www.google.com/chrome/
1 Comment |
Google, Software, Web Browsers | Tagged: Google, Software, Web Browsers |
Permalink
Posted by dotnetcoderoom
September 2, 2008
How to rename a MS SQL server database table column name after the table creation??
You can rename a column regardless of it is null or contains any data.
We need to use a System stored procedure to rename. Any command with alter keywords won’t work.
Code
EXEC sp_rename ‘tableName.[oldColumnName]‘, ‘newColumnName’, ‘COLUMN’
Example:
EXEC sp_rename ‘Ultra_tblPressRelease.[uShowStatus]‘, ‘uShowInA2B’, ‘COLUMN’
The above line will rename the existing column named uShowStatus of table tblPressRelease to uShowInA2B.
There will be no adverse effect of this procedure on your table data.
But you have to update all your SQL Cursors and Stored Procedures with the new column name (if any).
Leave a Comment » |
DataBase, MS SQL, MS SQL Stored Procedures, SQL Cursors | Tagged: DataBase, MS SQL, MS SQL Stored Procedures, SQL Cursors |
Permalink
Posted by dotnetcoderoom