Saturday, June 21, 2008
LTrim, RTrim, IsNumeric function in Javascript
One of the function is LTRIM. This function is used to remove spaces from the left of the string. this function accept one string and remove all spaces from left side and return string.
Here is the defination :-
function LTrim( value ) {
var re = /\s*((\S+\s*)*)/;
return value.replace(re, "$1");
}
Rtrim function is used to remove ending spaces through javascript.
Here is coding :-
// Removes ending whitespaces
function RTrim( value )
{
var re = /((\s*\S+)*)\s*/;
return value.replace(re, "$1");
}
isNumeric function is used to check string is numeric or not.
here is this code.
function IsNumeric(strString)
// check for valid numeric strings
{
var strValidChars = "0123456789.";
var strChar;
var blnResult = true;
if (strString.length == 0) return false;
// test strString consists of valid characters listed above
for (i = 0; i < strString.length && blnResult == true; i++)
{
strChar = strString.charAt(i);
if (strValidChars.indexOf(strChar) == -1)
{
blnResult = false;
}
if(strChar==".")
{
strValidChars = "0123456789";
}
}
return blnResult;
}
Monday, June 16, 2008
Solution of "Cannot get inner content of your DIV because the contents are not literal. "
Solution is :-
StringWriter sw = new StringWriter();
HtmlTextWriter h= new HtmlTextWriter(sw);
objDiv.RenderControl(h);
string str= sw.GetStringBuilder().ToString();
* objDiv is your DIV Id.
Thanks
Saturday, June 14, 2008
Export ASP.NET page to Word, Excel or HTML
Here is the code for “Export ASP.NET page to Word, Excel or html. “
Firstly, you will import System.IO
Imports System.IO
After this you will write below code
Response.Clear(); //this clears the Response of any headers or previous output
Response.Buffer = true; //make sure that the entire output is rendered simultaneously
///
///Set content type to MS Excel sheet
///Use “application/msword” for MS Word doc files
///“application/pdf” for PDF files
///
Response.ContentType = “application/vnd.ms-excel”;
StringWriter stringWriter = new StringWriter(); //System.IO namespace should be usedHtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);///
///Render the entire Page control in the HtmlTextWriter object
///We can render individual controls also, like a DataGrid to be
///exported in custom format (excel, word etc)
///
this.RenderControl(htmlTextWriter);
Response.Write(stringWriter.ToString());
Response.End();
Friday, June 13, 2008
Email sending code in .Net
Here is the example:-
Firstly, You import
Imports System.Web.Mail
Then Write Code
Dim msg As New Mail.MailMessage
msg.From = ”kamal.jindal@gharexpert.com“
msg.To = ”jindal82@gmail.com“
msg.BodyFormat = MailFormat.Html
msg.Body = “I am writing article of Sending Email with .NET page”
msg.Subject = “Sending Email with .NET page”
SmtpMail.Send(msg)
Thanks