Search This Blog

Saturday, May 30, 2015

Get the checkbox value is checked or not using Jquery

 $(document).ready(function () {
    $('#<%=chkValidateBabyName.ClientID%>').change(function () {
          if ($(this).is(":checked")) {
            alert("Check box checked");
          }
          else{
           alert("Check box un checked");
         }
    });
});

Include this code in document ready function. then you will get checkbox value when the check box value is changed..

Friday, May 29, 2015

Select Values from sql table with auto generated Serial number


select ROW_NUMBER() OVER (order by Modified_On desc) as SerialNumber, Name from StudentDetails

Monday, May 25, 2015

How to create a static variable at client side

Actually we cant create a static variable at client side. But we can keep the value even after page postback using Hidden field control.

First we need to create a hidden control and need to set ClientIDMode as "Static"

Ex: <asp:HiddenField ID="hndControl" ClientIDMode="Static" runat="server" />

After that we need to assign the value to that hidden field.

document.getElementById('<%= hndControl.ClientID %>').value = "Static";

Here after we can use that value until we change hidden field value.



Sunday, May 24, 2015

How to avoid alphabets and special character from text box using javascript

Use the following code OnKeyPress Event in your text box:

<asp:TextBox ID="txtNumber" runat="server" OnKeyPress="return IsNumeric(event);"></asp:TextBox>


function IsNumeric(e) {
    var keyCode = e.which ? e.which : e.keyCode
    var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1);
    document.getElementById("error").style.display = ret ? "none" : "inline";
    //TestOnTextChange();
    return ret;
}

Disable Copy, Cut and Paste options in text box

Include the following options in your text box:

onpaste="return false"
oncut="return false"
oncopy="return false"

it will avoid the cut, copy and paste options from your text box

Friday, May 22, 2015

DataTable does not contain definition for AsEnumerable


The method you want is in the System.Data namespace, so that using directive is fine, but you also need a reference to the System.Data.DataSetExtensions assembly.

Thursday, May 21, 2015

Timer Job Issues


This is the most common error in timer job.

Keep your scope as site

  public override void FeatureActivated(SPFeatureReceiverProperties properties)
  {
            SPSite site = properties.Feature.Parent as SPSite;
}

get the site as mentioned above.

If still you get the same error please check your code whether you are using any custom dll.
Because timer job sometimes will not accept custom dll files. so try to avoid those.



Wednesday, May 20, 2015

Timer Job with Sharepoint

Timer Job:

Timer Job is a background process that are run by SharePoint. It is a periodically executed task inside SharePoint Server. It provides us a task execution environment.

Default Timer Jobs inside SharePoint:

There are many timer jobs inside SharePoint which do internal tasks like:
    • Send emails
    • Validate sites
    • Delete unused sites
    • Health analysis
    • Product versioning
    • Diagnostics
These tasks will having execution periods like:
    • Minute
    • Hour
    • Day
    • Week
    • Month
Components of Connectable web parts : 
  1. Derive CustomTimerJob Class from SPJobDefinition
  2. Add the three Constructors of the derived class : When ever we create the object of CustomTimerJob  class, corresponding constructor will execute.
  3. Override the Execute method: When ever the timer job start running then the code inside the Execute method will run.
  4. We need to create a Feature and Feature Receiver so on activation of this feature we are going the add our timer job to SharePoint farm.

Sunday, May 10, 2015

Update managed meta data values into SPList

using (SPSite site = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    TaxonomySession taxonomySession = new TaxonomySession(site);
                    TermStore termStore = taxonomySession.TermStores["Test_ManagedMetaData"];
                    Group group = termStore.Groups["College"];
                    TermSet termSet = group.TermSets["Karur"];
                    Term term = termSet.Terms["CCET"];
                    SPList list = web.Lists.TryGetList("TimerJobList");
                    if (list != null)
                    {
                        TaxonomyField taxonomyField = list.Fields["College"] as TaxonomyField;
                        TaxonomyFieldValue taxonomyFieldValue = new TaxonomyFieldValue(taxonomyField);
                        taxonomyFieldValue.TermGuid = term.Id.ToString();
                        taxonomyFieldValue.Label = term.Name;
                        SPListItem item = list.Items.Add();
                        item["Title"] = "Sample";
                        item["College"] = taxonomyFieldValue;
                        item.Update();
                        //list.Update();
                    }
                }
            }

Restricting Custom People Picker to only one Sharepoint group programatically

Refer the following script files in your page,     <!-- For People Picker -->     <script type="text/javascript" src...