October 31, 2012

Add or remove css using javascript


Encapsulation is one of the main concepts in object oriented programming. It allows an object to group both private and public members under a single name. All the object oriented programming languages support this. Since JavaScript is also an object oriented programming language, it supports it too.
/*
* This class helps to add / remove / swap css files dynamically.
*/

var Managers = {}; //namespace

Managers.CssManager = (function(){ //Singleton class

//Private members
var doc = document;
var setAttributes = function(element, attributes){
for(attribute in attributes){
element[attribute] = attributes[attribute];
}
}

return{
//Public members
addStyleSheet: function(id, url){
var newStyleSheet = doc.createElement(“link”);
setAttributes(newStyleSheet, {
rel : “stylesheet”,
type : “text/css”,
id : id,
href: url
});
doc.getElementsByTagName(“head”)[0].appendChild(newStyleSheet);
},

removeStyleSheet: function(id){
var currentStyleSheet = doc.getElementById(id);
if(currentStyleSheet){
currentStyleSheet.parentNode.removeChild(currentStyleSheet);
}
},

swapStyleSheet: function(id, url){
this.removeStyleSheet(id);
this.addStyleSheet(id, url);
}
}
})();

 

Save above code as .js extension.

 

To add stylesheet to your page use,

Managers.CssManager.addStyleSheet("myStyleSheet", "Stylesheet1.css");

You can remove/replace using

Managers.CssManager.removeStyleSheet("myStyleSheet");
Managers.CssManager.swapStyleSheet("myStyleSheet", "Stylesheet2.css");

You can create you own function to add js file reference same like this.


April 12, 2012

Blackberry technical doc


http://www.sybase.com/files/Technical_Documents/UltraLiteJ_Tutorial.pdf

November 12, 2011

Custom input filter using jQuery/Javascript


$(function () {
$(document).ready(function () {
$(‘.ANSP’).keyup(function () {
if (this.value.match(/[^a-zA-Z0-9 ]/g)) {
this.value = this.value.replace(/[^a-zA-Z0-9 ]/g, ”);
}
});

$(‘.AN’).keyup(function () {
if (this.value.match(/[^a-zA-Z0-9]/g)) {
this.value = this.value.replace(/[^a-zA-Z0-9]/g, ”);
}
});

$(‘.ASP’).keyup(function () {
if (this.value.match(/[^a-zA-Z ]/g)) {
this.value = this.value.replace(/[^a-zA-Z ]/g, ”);
}
});

$(‘.A’).keyup(function () {
if (this.value.match(/[^a-zA-Z]/g)) {
this.value = this.value.replace(/[^a-zA-Z]/g, ”);
}
});

$(‘.N’).keyup(function () {
if (this.value.match(/[^0-9]/g)) {
this.value = this.value.replace(/[^0-9]/g, ”);

}
});

$(‘.ND’).keyup(function () {
if (this.value.match(/[^0-9.]/g)) {
this.value = this.value.replace(/[^0-9.]/g, ”);
}
});

});
});

November 12, 2011

Rounded corner control using css


To create rounded corner table(support in all major browser)

Style

.curved-box
{
/*width: 9em;
border-top-left-radius: 10pt 10pt;
border-top-right-radius: 10pt;*/
padding: 10px;
background-color: #F0F0F0;
-moz-border-radius: 10px;
border-radius: 10px;
-webkit-border-radius: 10px;
}

<table width=”100%” class=”curved-box”>

<tr>

<td>

write your contents here…

</td>

</tr>

</table>

November 3, 2011

Only Number allowed.


Enable only Numbers & Dot using Javascript

function inputOnlyNumbers(evt){
var e = window.event || evt; // for trans-browser compatibility
var charCode = e.which || e.keyCode;
if ((charCode > 45 && charCode < 58) || charCode == 8){
return true;
}
return false;
}

The Code to be used in HTML page to enable only numbers & dots as shown below.

<input name=”weight” size=”15″ id=”weight” tabindex=”9″ type=”text” maxlength=”5″ onkeypress=”return inputOnlyNumbers(event)”/>

If we want to enable only numbers without the dot…..
just change the if condition in Javascript as shown below.

if ((charCode > 47 && charCode < 58) || charCode == 8)

 

October 14, 2011

SQL SERVER – @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record


SELECT @@IDENTITY
It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.
@@IDENTITY will return the last identity value entered into a table in your current session. While @@IDENTITY is limited to the current session, it is not limited to the current scope. If you have a trigger on a table that causes an identity to be created in another table, you will get the identity that was created last, even if it was the trigger that created it.

SELECT SCOPE_IDENTITY()
It returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value.
SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function.

SELECT IDENT_CURRENT(‘tablename’)
It returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.
IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.


October 6, 2011

jQuery, and CSS Progressing/Loading Bar


.aspx content

<div id=”win1″ class=”win” style=”display: none;”>

<br />
<asp:Label ID=”lblProcessing” Text=”&nbsp;Processing…” runat=”server”></asp:Label><br />
<asp:Image ID=”imgProcessing” ImageAlign=”absMiddle” ImageUrl=”~/Image/loader.gif”
runat=”server” />
</div>
<div id=”divMask” class=”Mask” style=”height:600px;width:1350px;”>
</div>

.Css Content

//window style

.win
{
width: 230px;
height: 75px;
margin: 0 auto;
border: 5px solid white;
background: none repeat scroll 0 0 #EBECEE;
position: fixed;
top: 300px;
left: 40%;
z-index:15;
padding: 10px;
text-align:left;
font-weight:bold;
}

//gray background style

.Mask
{
background-color: gray;
display: none;
left: 0;
position: absolute;
top: 0;
z-index: 10;
opacity: 0.5;
}

.js Content

function Show_Pop() {
document.getElementById(“win1″).style.display = ”;
document.getElementById(“divMask”).style.display = ‘block';

}

function Close_Pop() {
document.getElementById(“win1″).style.display = ‘none';
document.getElementById(“divMask”).style.display = ”;

}

September 20, 2011

Adding and Removing Text Box Dynamically using JavaScript


<html>
<head>
<title>Adding and Removing Text Boxes Dynamically</title>
<script type=”text/javascript”>
var intTextBox1=0;
var intTextBox2=0;
var intTextBox3=0;
var intTextBox4=0;
function addElement()
{
intTextBox1 = intTextBox1 + 1;
intTextBox2 = intTextBox2 + 1;
intTextBox3 = intTextBox3 + 1;
intTextBox4 = intTextBox4 + 1;

var contentID = document.getElementById(‘content’);
var newTBDiv = document.createElement(‘div’);
newTBDiv.setAttribute(‘id’, ‘strText’ + intTextBox1);
var dv = “Text ” + intTextBox1 + “: <input type=’text’ id=’f” + intTextBox1 + “‘ name=’f” + intTextBox1 + “‘/>&nbsp;&nbsp;”;
dv += “Text ” + intTextBox2 + “: <input type=’text’ id=’s” + intTextBox2 + “‘ name=’s” + intTextBox2 + “‘/>&nbsp;&nbsp;”;
dv += “Text ” + intTextBox3 + “: <input type=’text’ id=’t” + intTextBox3 + “‘ name=’t” + intTextBox3 + “‘/>&nbsp;&nbsp;”;
dv += “Text ” + intTextBox4 + “: <input type=’text’ id=’f” + intTextBox4 + “‘ name=’f” + intTextBox4 + “‘/>&nbsp;&nbsp;”;
newTBDiv.innerHTML = dv;
contentID.appendChild(newTBDiv);
}
function removeElement()
{
if(intTextBox1 != 0)
{
var contentID = document.getElementById(‘content’);
contentID.removeChild(document.getElementById(‘strText’+intTextBox1));
intTextBox1 = intTextBox1 – 1;

contentID.removeChild(document.getElementById(‘strText’ + intTextBox2));
intTextBox2 = intTextBox2 – 1;

contentID.removeChild(document.getElementById(‘strText’ + intTextBox3));
intTextBox3 = intTextBox3 – 1;

contentID.removeChild(document.getElementById(‘strText’ + intTextBox4));
intTextBox4 = intTextBox4 – 1;
}

}
</script>
</head>
<body>
<p>Adding and Removing Text Box Dynamically using JavaScript</p>
<p><a href=”javascript:addElement();” >Add</a> <a href=”javascript:removeElement();” >Remove</a></p>
<div id=”content”></div>
</body>
</html>

September 12, 2011

Send E-mail using SMTP Server


public void sendemail()

{

string Subject = “Mail Subject”;
string To = email;
string emailBody = generateEmailBody(Lst);
MailMessage MMsg = new MailMessage();
MMsg.To = To;
MMsg.Subject = Subject;
MMsg.Priority = MailPriority.Normal;
MMsg.BodyFormat = MailFormat.Html;
MMsg.Body = emailBody;
try
{
Base.SMTPSend(MMsg);
}
catch (Exception)
{

}

}

 

public static bool SMTPSend(MailMessage mail)
{
bool ret = false;
string adminEmail = string.Empty;
string SmtpHost = string.Empty;
string SmtpUserName = string.Empty;
string SmtpPassword = string.Empty;
string strQry = “select * from Configuration”;
DataTable dt = SQLHelper.ExecuteDataSet(System.Data.CommandType.Text, strQry).Tables[0];
if (dt.Rows.Count > 0)
{
mail.From = adminEmail = Convert.ToString(dt.Rows[1][“ConfigValue”]);
SmtpHost = Convert.ToString(dt.Rows[2][“ConfigValue”]);
SmtpUserName = Convert.ToString(dt.Rows[3][“ConfigValue”]);
SmtpPassword = Convert.ToString(dt.Rows[4][“ConfigValue”]);
}
try
{
mail.Fields.Add(“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate&#8221;, “1”);
mail.Fields.Add(“http://schemas.microsoft.com/cdo/configuration/sendusername&#8221;, SmtpUserName);
mail.Fields.Add(“http://schemas.microsoft.com/cdo/configuration/sendpassword&#8221;, SmtpPassword);
mail.Fields.Add(“http://schemas.microsoft.com/cdo/configuration/sendusing&#8221;, “2”);
mail.Fields.Add(“http://schemas.microsoft.com/cdo/configuration/smtpserver&#8221;, SmtpHost);
mail.Fields.Add(“http://schemas.microsoft.com/cdo/configuration/smtpserverport&#8221;, 25);
System.Web.Mail.SmtpMail.SmtpServer = SmtpHost;
SmtpMail.Send(mail);
ret = true;
}
catch (Exception ex)
{
//Log.Write(“EmailBase.SMTPSend ” + ex.Message.ToString());
}
return ret;
}

August 25, 2011

How to set Html Meta Description and Content in Code Behind


        HtmlMeta metaDesc = new HtmlMeta();
        metaDesc.Name = "description";
        HtmlMeta metaKeywords = new HtmlMeta();
        metaKeywords.Name = "keywords";
        metaDesc.Content = "metaDesc content";
        metaKeywords.Content = "metaKeywords content";
        Page.Title = "page Title";
        HtmlHead head = (HtmlHead)Page.Header;
        head.Controls.AddAt(1, new LiteralControl("\n"));
        head.Controls.AddAt(2, metaDesc);
        head.Controls.AddAt(3, new LiteralControl("\n"));
        head.Controls.AddAt(4, metaKeywords);
        head.Controls.AddAt(5, new LiteralControl("\n"));
Follow

Get every new post delivered to your Inbox.