Thursday, July 31, 2014

Redirecting to a page after adding a New item to a list

There are times when you want a user to add an item to a list without displaying the list, either before or after they fill out the “New Item” form.
 image
To get them to the form is easy. Go to the list, click the New button and note the URL. Copy the URL and paste it as a link in Quick Launch, an Announcement, a links list or a Content Editor Web Part.
image
When the user clicks your link they will go directly to the New item page. But… when they click OK they will go to the list, not back to your page.
 image

The fix is easy...        Add “source=” to the end of the link.

1) Go to the list and click the new button. You will see a URL like:

2) copy the URL and change the part after Source= to the desired destination. The following will send them back to your home page:

Absolute or Relative?
Best practice would be to use a relative URL (no HTTP or server name) so your site will work when you have internet and intranet access to the same site. Something like "Source=/sites/sales/" or "Source=/sites/sales/mycustompage.aspx".
To return to the home page add this URL as a link in your Announcement, a links list or a Content Editor Web Part:
Absolute:
Relative:

In the examples above I did not always escape the slashes:  /  =  %2F
Any slash after the "?" should be escaped.


Redirect the Cancel Button

One of the questions below notes that the redirect steps above redirect both the OK and the Cancel button to the “Source” URL.  Here’s is a quick pass at adding a “CancelDestination” parameter to the query string to set the destination for the cancel button.
Steps:
  1. Go the “New Item” page
  2. Edit the URL and add “&ToolPaneView=2” to the end of the URL to put the page in edit mode
     
    http://yourserver/sites/sales/Lists/Announcements/NewForm.aspx?RootFolder=%2fsites%2fsales%2fLists%2fAnnouncements&Source=http%3a%2f%2fyourserver%2fsales%2fyoursite&ToolPaneView=2
     
  3. Click “Add a Web Part” and add a Content Editor Web Part (CEWP)
  4. Move the CEWP below the existing list web part
  5. Edit the CEWP and click the Source Editor button
  6. Paste the JavaScript from below
  7. Save your changes and exit the edit mode of the page
  8. Create a URL similar to the one earlier in the article, but add a new parameter named “&CancelDestination=http://yourcanceldestination"
     
    http://www.yourserver.com/sites/sales/Lists/Tasks/NewForm.aspx?RootFolder=%2FLists%2FTasks&Source=http%3A%2F%2Fwww.yourserver.com%2Fsites%2Fsales&CancelDestination=http%3A%2F%2Fwww.yourserver.com%2Fsites%2Fsales%2FCancelPage.aspx
     
  9. Test!

The JavaScript:
<script>

var querystring = window.location.search.substring(1);  
var parameters = querystring.split("&");
var QueryString = Array();
for (var i=0;i<parameters.length;i++)
{
  QueryString[parameters[i].split("=")[0]] = parameters[i].split("=")[1];
}
if (QueryString["CancelDestination"] != undefined)
{
  var inputs = document.getElementsByTagName("INPUT");
  for (var i=0; i<inputs.length; i++)
  {
    if (inputs[i].value == "Cancel")
    {
      inputs[i].onclick =
       function () {document.location.href = unescape(QueryString["CancelDestination"])};
    }
  }
}
</script>


Reference:

Thursday, July 24, 2014

Set MaxLength for Multiline TextBox in ASP.Net using jQuery

Implementing the jQuery MaxLength Plugin for ASP.Net MultiLine TextBox (TextArea)
Below you will notice the implementation of the jQuery MaxLength plugin. The jQuery MaxLength plugin has the following required and optional parameters
1. MaxLength (required) – Integer value indicating the Maximum character length limit.
2. CharacterCountControl (optional) – By default the plugin will display character count below the TextArea, but user has option to explicitly specify the Character Count Control.
Note: The character count control can only HTML SPAN or DIV.
3. DisplayCharacterCount (optional) – Default true. If set to false the Character counting will be disabled.
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">script>
    <script type="text/javascript" src="MaxLength.min.js">script>
    <script type="text/javascript">
        $(function () {
            //Normal Configuration
            $("[id*=TextBox1]").MaxLength({ MaxLength: 10 });
 
            //Specifying the Character Count control explicitly
            $("[id*=TextBox2]").MaxLength(
            {
                MaxLength: 15,
                CharacterCountControl: $('#counter')
            });
 
            //Disable Character Count
            $("[id*=TextBox3]").MaxLength(
            {
                MaxLength: 20,
                DisplayCharacterCount: false
            });
        });
    script>
head>
<body>
    <form id="form1" runat="server">
    <div id="counter">
    div>
    <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Width="300" Height="100"
        Text="Mudassar Khan">asp:TextBox>
    <br />
    <br />
    <asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine" Width="300" Height="100">asp:TextBox>
    <br />
    <br />
    <asp:TextBox ID="TextBox3" runat="server" TextMode="MultiLine" Width="300" Height="100">asp:TextBox>
    form>
body>
html>


Reference:

Monday, July 21, 2014

Check Uncheck all items in ASP.Net CheckBoxList using jQuery

<asp:CheckBox ID="chkAll" Text="Select All" runat="server" />
<asp:CheckBoxList ID="chkFruits" runat="server">
    <asp:ListItem Text="Mango" />
    <asp:ListItem Text="Apple" />
    <asp:ListItem Text="Banana" />
    <asp:ListItem Text="Pineapple" />
    <asp:ListItem Text="Guava" />
    <asp:ListItem Text="Grapes" />
    <asp:ListItem Text="Papaya" />
</asp:CheckBoxList>


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("[id*=chkAll]").bind("click"function () {
            if ($(this).is(":checked")) {
                $("[id*=chkFruits] input").attr("checked""checked");
            } else {
                $("[id*=chkFruits] input").removeAttr("checked");
            }
        });
        $("[id*=chkFruits] input").bind("click"function () {
            if ($("[id*=chkFruits] input:checked").length == $("[id*=chkFruits] input").length) {
                $("[id*=chkAll]").attr("checked""checked");
            } else {
                $("[id*=chkAll]").removeAttr("checked");
            }
        });
    });
</script>

Reference:

Calling javascript function from CS page

Calling javascript function from CS page

var message = "<script type=text/javascript>SaveDraft();</script>";
             System.Web.UI.ClientScriptManager clientScriptManager = Page.ClientScript;
             clientScriptManager.RegisterStartupScript(this.GetType(), "Add", message);

or

var message = "<script type=text/javascript>alert('TemplateName already exists, please change the name');</script>";
                        System.Web.UI.ClientScriptManager clientScriptManager = Page.ClientScript;
                        clientScriptManager.RegisterStartupScript(this.GetType(), "Message", message);


ASPX page
function SaveDraft() {
        alert('Support details saved successfully!');
        }

Friday, July 18, 2014

SharePoint Navigation Providers


I want to share with you all, about navigation features in both WSS3.0 and MOSS. SharePoint Navigation features called Navigation Providers are enabled in the root directory of webapplications’s web.config file to access widely. These named Navigation providers are added to the <SiteMap> element under <System.Web> Section.
Named Providers are defined under WSS3.0 are,
· SPNavigationProvider
· SPSiteMapProvider
· SPContentMapProvider
· SPXmlContentMapProvider
· SPXmlAdminContentMapProvider*
*This named procedure only available in Central Administration webapplication
All the above providers share the same namespace called Microsoft.SharePoint.Navigation
MOSS included some named providers in addition to the WSS3.0 named providers.
· AdministrationQuickLaunchProvider
· SharedServicesQuickLaunchProvider
· GlobalNavSiteMapProvider
· CombinedNavSiteMapProvider
· CurrentNavSiteMapProvider
· CurrentNavSiteMapProviderNoEncode
· MySiteMapProvider
· MySiteLeftNavProvider
· SiteDirectoryCategoryProvider
· UsagePagesSiteMapProvider

Provider Names:
AdministrationQuickLaunchProvider:
Assembly
Microsoft.Office.Server.UI
Namespace
Microsoft.Office.Server.UI
Class Name
Microsoft.Office.Server.Web.
AdministrationQuickLaunchProvider
Description
QuickLaunch navigation provider for the central administration site
Assembly Path
GAC
SharedServicesQuickLaunchProvider:
Assembly
Microsoft.Office.Server.UI
Namespace
Microsoft.Office.Server.UI
Class Name
Microsoft.Office.Server.Web.
SharedServicesQuickLaunchProvider
Description
QuickLaunch navigation provider for shared services administration sites
Assembly Path
GAC
PortalSiteMapProvider:
Assembly
Microsoft.SharePoint.Publishing
Namespace
Microsoft.SharePoint.Publishing.Navigation
Class Name
Microsoft.SharePoint.Publishing.Navigation.
PortalSiteMapProvider
Description
Provides PortalSiteMapNode objects that represent a merging of the Windows SharePoint Services 3.0SPNavigation store and dynamic site structure, including sites and pages. This Provider has four navigation providers to merge with WSS3.0 Providers.
Assembly Path
..\12\ISAPI\
*The each different value of NavigationType property in PortalSiteMapProvider object represents the following providers. There are Current, Global & Combined navigationtypes.
GlobalNavSiteMapProvider:
NavigationType: Global
Description: Include SPNavigationNodes from navigation in the TopNavigationBarcollection of Windows SharePoint Services; respect global inheritance and include or hide settings.
CombinedNavSiteMapProvider:
NavigationType: Combined
Description: This is attached to the global navigation or top navigation menu by default.
CurrentNavSiteMapProvider:
NavigationType: Current
Description: Gets the PortalSiteMapProvider object that is attached by default to the current navigation or Quick Launch, respect to current inheritance settings and include or hide settings.
CurrentNavSiteMapProviderNoEncode:
NavigationType: Current
EncodeOutput: false
Description: Gets the PortalSiteMapProvider object that is attached to the breadcrumb navigation by default.
*Gets or sets whether to HTML-encode the Title property of each PortalSiteMapNode object.
MySiteMapProvider:
Assembly
Microsoft.SharePoint.Portal
Namespace
Microsoft.SharePoint.Portal
Class Name
Microsoft.SharePoint.Portal.
MySiteMapProvider
Description
MySite provider that returns (MyProfile links) areas and based on the current user context.
Assembly Path
..\12\ISAPI\
MySiteLeftNavProvider:
Assembly
Microsoft.SharePoint.Portal
Namespace
Microsoft.SharePoint.Portal
Class Name
Microsoft.SharePoint.Portal.
MySiteLeftNavProvider
Description
MySite Left Nav provider that returns areas (Quick Launch) and based on the current user context.
Assembly Path
..\12\ISAPI\
SiteDirectoryCategoryProvider:
Assembly
Microsoft.SharePoint.Portal
Namespace
Microsoft.SharePoint.Portal.WebControls
Class Name
Microsoft.SharePoint.Portal.WebControls.
SiteDirectoryCategoryProvider
Description
SiteDirectory Category Provider returns the Category nodes present in the SiteDirectory Sites.
Assembly Path
..\12\ISAPI\
UsagePagesSiteMapProvider:
Assembly
Microsoft.SharePoint.Portal
Namespace
Microsoft.SharePoint.Portal.Analytics
Class Name
Microsoft.SharePoint.Portal.Analytics.
UsagePagesSiteMapProvider
Description
Provider for navigation in Portal Usage pages
Assembly Path
..\12\ISAPI\
SPNavigationProvider:
Assembly
Microsoft.SharePoint
Namespace
Microsoft.SharePoint.Navigation
Class Name
Microsoft.SharePoint.Navigation.
SPNavigationProvider
Description
Provides a base class for Windows SharePoint Services site-map providers that are specialized for SharePoint site navigation.
Node “sid:1002” represents the QuickLaunchBar,
Node “sid:1025” represents the TopNavigationBar
Assembly Path
..\12\ISAPI\
SPSiteMapProvider:
Assembly
Microsoft.SharePoint
Namespace
Microsoft.SharePoint.Navigation
Class Name
Microsoft.SharePoint.Navigation.
SPSiteMapProvider
Description
Provides the SiteMapNode objects that constitute the global content breadcrumb, which represents objects in the site hierarchy above the current site.
Assembly Path
..\12\ISAPI\
SPContentMapProvider:
Assembly
Microsoft.SharePoint
Namespace
Microsoft.SharePoint.Navigation
Class Name
Microsoft.SharePoint.Navigation.
SPContentMapProvider
Description
Provides methods and properties for implementing a site map provider for contents of a Windows SharePoint Services site. This class provides the SiteMapNode objects that constitute the content breadcrumb, where “content” referes to the lists, folders, items, and list forms composing the breadcrumb.
Assembly Path
..\12\ISAPI\
SPXmlContentMapProvider:
Assembly
Microsoft.SharePoint
Namespace
Microsoft.SharePoint.Navigation
Class Name
Microsoft.SharePoint.Navigation.
SPXmlContentMapProvider
Description
Provides methods and properties for implementing a site map provider for contents of a Windows SharePoint Services site. This class provides the SiteMapNode objects that constitute the content breadcrumb, where “content” referes to the lists, folders, items, and list forms composing the breadcrumb.
Site-Map Path
../ApplicationRootDirectory/_app_bin/layouts.sitemap
SPXmlAdminContentMapProvider:
Available to only Central Administration application
Assembly
Microsoft.SharePoint
Namespace
Microsoft.SharePoint.Navigation
Class Name
Microsoft.SharePoint.Navigation.
SPXmlContentMapProvider
Description
Provides methods and properties for implementing a site map provider for contents of a Windows SharePoint Services site. This class provides the SiteMapNode objects that constitute the content breadcrumb, where “content” referes to the lists, folders, items, and list forms composing the breadcrumb.
Site-Map Path
../CentralAdministrationRootDirectory/_app_bin/admin.sitemap
soon I will come with a deep details about each navigation Providers.

Image noise comparison methods

 1. using reference image technique     - peak_signal_noise_ratio (PSNR)     - SSI 2. non-reference image technique     - BRISQUE python pac...