Wednesday 27 February 2013

Disable mouse right click using javascript


When we right click on the page and click on the view source option then page html source along with inline css will see. From the source code, they can figure out how you did things and where your graphics are stored, or just plain old copy your content coding. To prevent the user to know the source detail we disable right click on the page.

<script type="text/javascript">
        var message = "Right Click Disabled!";
        function DisableIE() {
            if (event.button == 2) { alert(message); return false; }
        }
        function DisableOther(e) {
            if (document.layers || document.getElementById && !document.all)
            { if (e.which == 2 || e.which == 3) { alert(message); return false; } }
        }
        if (document.layers) { document.captureEvents(Event.MOUSEDOWN); document.onmousedown = DisableOther; }
        else if (document.all && !document.getElementById) { document.onmousedown = DisableIE; }
        document.oncontextmenu = new Function("alert(message);return false")
</script>

Disable F12 key in the browser


When user press F12 key, browsers developer tool bar will open in the below portion of the browser. By
using the developer tool bar user can see the design, javascript code and corresponding css applied to the controls in the page. To prevent the user to do that we will the hide developer tool bar.

You can use the below code to do that. Write the below code in the head section of the page.
<script type="text/javascript">

document.onkeydown = function (event)
{
     event = (event || window.event);
     if (event.keyCode == 123 || event.keyCode == 18)
     {
           alert("This function is disabled here");
           return false;
     }
}
</script>

Monday 25 February 2013

Request format is unrecognized for URL unexpectedly ending in


Add the following to web.config since GET and POST are disabled by default in ASP.NET 2.0 and greater:

<configuration>
    <system.web>
    <webServices>
        <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
    </system.web>
</configuration>

Build the project and run.

Sunday 24 February 2013

Show Logo on Title Bar

1 - Take a small logo image of 16*16 pixel.
2 - Put that image in the image folder of the project.
3 - In the master page write the below line.
      <link type="image/x-icon" rel="Logo" href="Image/sanjeet.ico" />
      Here my icon name is sanjeet.ico.
4 - Press F5 to run your project.

The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service. For more information, contact your server administrator.


You may receive this error when trying to publish a infopath form in SharePoint 2010.

The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service. For more information, contact your server administrator.

Cause :
State service is not enabled on Server.You would need to install the ‘State Service’ via the Configuration wizard in Central Administration or via PowerShell.

Before configure the settings check by using following steps.
1. Go to "Application Management" --> "Manage service applications"
2. Check whether the "State Service" is enabled or not
3. If the service is not started or missed, we should configure/start the state service. OK.

Configure the State Service using the Farm Configuration Wizard
1- Open Central Administration. Click on Configuration Wizards option from left navigation.

2 - Click on the "Launch the Farm Configuration Wizard" option from RHS.

3 -  Click on the "Start the Wizard" button.

4 - On the services configuration page, in the Services section, select the State Service check box (and/or any other services you might be interested) and click Next.

5 - If you set-up a top-level site already click on Skip button if not go ahead and create it now by clicking OK.

6 - On the final page of the Farm Configuration Wizard, review your freshly installed services and click Finish.

Configure the State Service using Windows PowerShell
1 - Open SharePoint 2010 Management Shell.
2 - To create a service application, type the following command:
      $serviceApp = New-SPStateServiceApplication -Name "State Service"
3 - Create a State Service database and associate it with a service application, by typing:
      New-SPStateServiceDatabase -Name "StateServiceDatabase" -ServiceApplication $serviceApp
4 - Create a State Service Application Proxy and associate it with the service application by typing:
      New-SPStateServiceApplicationProxy -Name "State Service" -ServiceApplication $serviceApp -   DefaultProxyGroup

Friday 15 February 2013

List Join in SharePoint 2010 using CAML

1. Create a list Department and enter some values in it.
 
2. Create a list "Employee". Here create a column department and make it as look up column of Department -> Title. Enter some values in it.
 
3. Create a web part using visual studio and deploy.
   a) Drag and drop a grid view from tool box in the designing part.
   b) Write the below code to join the list.

       Code:
       using (SPSite site = new SPSite("http://win-j9h3l62i2n9:1000/"))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList list = web.Lists["Employee"];

                        SPQuery query = new SPQuery();
                        query.Query = @"<Query><Where><Eq><FieldRef Name='Gender' /><Value Type='Choice'>Male</Value></Eq></Where></Query>";

                        query.Joins = @"<Join Type='INNER' ListAlias='Department'>
                                            <Eq>
                                               <FieldRef Name='Department' RefType='ID' />
                                               <FieldRef List='Department' Name='ID' />
                                            </Eq>
                                        </Join>";

                        query.ProjectedFields =
                             @"<Field Name='Dep_Code' Type='Lookup' List='Department' ShowField='Title' />
                               <Field Name='Dep_Name' Type='Lookup' List='Department' ShowField='Name' />
                               <Field Name='Dep_Comment' Type='Lookup' List='Department' ShowField='Comment' />";

                        query.ViewFields = @"<FieldRef Name='Gender' />
                                             <FieldRef Name='Dep_Code' />
                                             <FieldRef Name='Dep_Name' />
                                             <FieldRef Name='Dep_Comment' />";

                        query.RowLimit = 100;

                        SPListItemCollection items = list.GetItems(query);

                        DataTable dt = items.GetDataTable();

                        grdShow.DataSource = dt;
                        grdShow.DataBind();
                    }
                }
 
4. Build and deploy.

Monday 4 February 2013

How to Add the Reference of a User Control in the webconfig file in ASPNET

At the time of working, developers register the User Controls to individual asp.net pages where, controls are in use. If the control is in use in most of the pages of the site, the reference can be added at one place only, that is in the web.config.

Code to add in web.config file to register the user control
<configuration>
  <system.web>
    <pages>
      <controls>
        <add tagPrefix="uc1" src="~/usercontrols/Address1.ascx" tagName="Address1"/>
        <add tagPrefix="uc2" src="~/usercontrols/Address2.ascx" tagName="Address2"/>
      </controls>
    </pages>
  </system.web>
</configuration>

Code to use the user control in the page
Open your aspx page and place the below code.

<uc1:Address1 ID="ucAddress1" runat="server"/>
<uc2:Address2 ID="ucAddress2" runat="server"/>