Avoid Sapce in textbox starting



function trimstring(ctrl, Key) {

if (Key.charAt(0) == ” “) {
document.getElementById(ctrl).value = document.getElementById(ctrl).value.trim();


<asp:TextBox ID=”txtFirstName” MaxLength=”50″ onKeyUp=”trimstring(this.id,this.value);” runat=”server”></asp:TextBox><br />


Posted in Uncategorized | Leave a comment

US Phone Number Validation

function validatephone(sender, args) {
document.getElementById(“<%= customvalidate.ClientID %>”).innerHTML = “”;
var txt1 = document.getElementById(“<%= txtbox1.ClientID %>”).value;
var txt2 = document.getElementById(“<%= txtbox2.ClientID %>”).value;
var txt3 = document.getElementById(“<%= txtbox3.ClientID %>”).value;

if ((txt1 != “”) && (txt1 == 3)) {

if ((txt2 != “”) && (txt2 == 3)) {

if ((txt3 != “”) && (txt3 == 4)) {
return args.IsValid = true;


else if ((txt1 == “”) && (txt2 == “”) && (txt3 == “”)) {

document.getElementById(“<%= customvalidate.ClientID %>”).innerHTML = “Please enter home phone(### ### ####)”;
return args.IsValid = false;

else if ((txt1.length < 3) || (txt2.length < 3) || (txt3.length < 4) || (txt1 == “000”)) {
document.getElementById(“<%= customvalidate.ClientID %>”).innerHTML = “Please enter valid home phone”;
return args.IsValid = false;

else {

return args.IsValid = true;


Html Side


<asp:TextBox ID=”txtBox1″ onKeyUp=”txtchangedp3();”
MaxLength=”3″ CssClass=”phone_width” runat=”server”></asp:TextBox>

<asp:TextBox ID=”txtBox2″ onKeyUp=”txtchangedp4();”
MaxLength=”3″ CssClass=”phone_width” runat=”server”></asp:TextBox>

<asp:TextBox ID=”txtBox3″ onKeyUp=”trimstring(this.id,this.value);” CssClass=”phone_width1″ MaxLength=”4″ runat=”server”></asp:TextBox><br />

<asp:CustomValidator ID=”customvalidate” runat=”server” ValidationGroup=”Patient”
ClientValidationFunction=”validatePhone” Display=”Dynamic”></asp:CustomValidator>

Posted in JavaScript | Leave a comment

Regular expression for Date Validation


regular Expression for Date Validation

<asp:RegularExpressionValidator runat=”server” ValidationGroup=”Patient” ID=”RegularExpressionValidator19″
ControlToValidate=”txtSPBlockOutDate” ErrorMessage=”Please enter valid date”
ValidationExpression=”(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(29|30)|(0?[13578]|1[02])/31)/(19|[2-9]\d)\d{2}|0?2/29/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))” />

Correct expression working fine…


Posted in JavaScript | Leave a comment

how to disable button in javascript after one click avoid duplicate entry

function disableButton(sender, group) {
if (Page_IsValid) {
sender.disabled = “disabled”;
__doPostBack(sender.name, ”);


<asp:ImageButton ID=”imgbtnSubmit”                                                                                                            ValidationGroup=”Patient” ToolTip=”Submit” runat=”server” OnClientClick=”disableButton(this,’Patient’)” OnClick=”imgbtnSubmit_Click”  />

Posted in JavaScript | Leave a comment

Insert/Retrive CheckBox Value to Sharepoint List


How to insert/Retrive a chekbox value to sharepoint list.

1.this checkbox contol in desingpage

<asp:CheckBoxList ID=”chkName” runat=”server” RepeatDirection=”Horizontal” Width=”100%”>
<asp:ListItem Text=”chk1″ Value=”0″></asp:ListItem>
<asp:ListItem Text=”chk2″ Value=”1″></asp:ListItem>
<asp:ListItem Text=”chk3″ Value=”2″></asp:ListItem>

2. create method called GetSelectedIDs(chkName)

public string GetSelectedIDs(CheckBoxList cblSelected)
string _SelectedIDs = null;
string chkid = null;
foreach (ListItem item in cblSelected.Items)
if (item.Selected)
_SelectedIDs += item.Value + “,”;
chkid = _SelectedIDs.ToString().Remove(_SelectedIDs.LastIndexOf(‘,’));
return chkid;

3. Then use this code whn insert a value to sharepoint list

protected void btnSubmit_Click(object sender, EventArgs e)

insertBL objins=new InsertBL(objhelp.GetSelectedIDs(chkTherapyName));





Same thing to Retrive the check value to sharepoint :

1. First create this method

public void chekedIDs(string divisionIDs, CheckBoxList cblDivision)
string[] GetdivisionIDs = divisionIDs.Split(‘,’);
for (int i = 0; i < GetdivisionIDs.Length; i++)

ListItem myListItem = cblDivision.Items.FindByValue(GetdivisionIDs[i]);
myListItem.Selected = true;

2.then use this code bind the value to checkbox

if (!string.IsNullOrEmpty(objget.Name))
objhelp.chekedIDs(objget.Name, chkName);

Posted in Sharepoint 2007 | Leave a comment

Ajax Tab Control CSS

This article explains us how to give own css style for Ajax TabContainer Control. 1. Create new ASP.NET AjaxEnabled Website. 2. Drag and Drop TabContainer Control from Toolkit to web form. 3. Drag and Drop TabPanel Control from Toolkit to … Continue reading

Gallery | Leave a comment

Sharepoint 2010 ECMAScript Client Object Model

Some Points about Sharepoint Client Object Model:

  • ECMAScript object model can only be used in SharePoint sites. So you can’t use this object model in an asp.net site to access SharePoint resources deployed in another url as this is cross-site scripting and not allowed.
  • You can’t use this object model in a SharePoint site to access resources in different SharePoint sites(i.e., different urls). For example, from mysite.mysp.com you can access resources in yoursite.yoursp.com using ECMAScript client OM. This is also cross-site scripting.
  • You can use JQuery with ECMAScript Client OM and for this you don’t need to do some extra work. All you need to do to use JQuery is to add reference to JQuery.js file and start using JQuery.
  • You can use this ECMAScript Client OM in web part pages or application pages (aspx pages) by referencing a javascript file (SP.js). You don’t need to add reference to the file manually rather use <SharePoint:ScriptLink Name=”sp.js” ………. />. The file is located on the path “Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS”
  • To update with JavaScript, you need to add a FormDigest tag in your page for security purpose. I’ll explain it later in details.

How to add the reference to SP.js and access the data?

Create a js file somewhere in the SharePoint site which can be accessible and write the below line as the first line.

  1. ExecuteOrDelayUntilScriptLoaded(initialize, “sp.js”);

Add the below line to the ASPX page.

<sharepoint:scriptlink localizable=”false” name=”SP.js” ondemand=”true” runat=”server”></sharepoint:scriptlink>

n javascript when you request files, all will load asynchronously. I mean, they will load randomly and what if your javascript is using sp.js file and it’s not loaded yet? This will be a problem. So, this method helps to tell the browser to wait and execute the “initialize” function if and only if sp.js file is loaded.

Note: If you are using the separate js file then paste the below code by removing the script tags. If you are using the script on ASPX page or in Content editor web part then copy all the code and paste.

Simple Example:

  1. <script type=”text/javascript”>
  2. ExecuteOrDelayUntilScriptLoaded(getWebSiteData, “sp.js”);
  3. var context = null;
  4. var web = null;
  5.     function getWebSiteData() {
  6.         context = new SP.ClientContext.get_current();
  7.         web = context.get_web();
  8.         context.load(web);
  9.         context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
  10.     }
  11.     function onSuccessMethod(sender, args) {
  12.         alert(‘web title:’ + web.get_title() + ‘\n ID:’ + web.get_id());
  13.     }
  14.     function onFaiureMethodl(sender, args) {
  15.         alert(‘request failed ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());
  16.     }
  17. </script>


Posted in Sharepoint Server 2010 | Leave a comment