How to Change Application Page Title Dynamically In C# Code Behind



TODO:

Have you ever wanted to change the title of your Application Page dynamically?

 

SOLUTIONS:

protected void SetPageTitles(string Title)
{
     ContentPlaceHolder contentPlaceHolder = (ContentPlaceHolder)Page.Master.FindControl("PlaceHolderPageTitle");
     contentPlaceHolder.Controls.Clear();
     LiteralControl title = new LiteralControl();
     title.Text = Title;
     contentPlaceHolder.Controls.Add(title);

     contentPlaceHolder = (ContentPlaceHolder)Page.Master.FindControl("PlaceHolderPageTitleInTitleArea");
     contentPlaceHolder.Controls.Clear();
     title = new LiteralControl();
     title.Text = Title;
     contentPlaceHolder.Controls.Add(title);
}

 

NOTES:

There are no notes on this topic.

How To Fix "Internet Information Services Is Not Installed" Error When Running SharePoint 2010 Products Configuration Wizard



TODO:

You run the SharePoint Products Configuration Wizard, and you receive the error "Internet Information Services Is Not Installed", even though you have IIS installed.  the issue is the IIS 6 features are not installed, and are required.

 

SOLUTION:

Install IIS6 features, and your issue will go away.

 

NOTES:

There are no notes on this topic.

How To Change The Virtual Directory Name From _Layouts To A Custom Value For Sharepoint Application Pages



TODO:

Have you ever wanted to change the location of your Application Pages from _Layouts to a directory that is more meaningful to your application?

 

SOLUTIONS:

1.  Open IIS Manager and go to your Sharepoint site.

2.  Create a new virtual directory at the same level as _layouts  (for example 'MyDirectoryName')

3.  Point the new virtual directory to the same physical path as your _layouts virtual directory. (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\template\layouts)

4.  Now open your application page, changing _layouts to MyDirectoryName.

5.  Now you have a more meaningful URL to use for your application pages.

 

NOTES:

What is nice about this solution, is that you do not need to do anything special during deployment.

Possible Cause For "Sys.ArgumentException: Value must not be null for Controls and Behaviors. Parameter name: element" When Using Telerik RadGrid



TODO:

You have a Telerik RadGrid and when you click on the Add button, you get the " Sys.ArgumentException: Value must not be null for Controls and Behaviors. Parameter name: element" error.

 

SOLUTION:

In my case I had the following structure:

Panel 1

FormGroup (a control we built)

Panel 2

RadGrid 1

 

I had AjaxSettings in my code behind for "Panel 1" and "FormGroup".  Having AjaxSettings for the nested controls caused my issue.  I removed the AjaxSetting for "FormGroup" and the issue went away


NOTES:

There are no notes on this topic.

Causes And Fixes For "Error: Sys.ArgumentNullException: Value cannot be null." In JQuery



TODO:

You make some changes the ASP.net controls on your form, and possible your JQuery.  You run your application and you end up with "Error: Sys.ArgumentNullException: Value cannot be null."  

 

SOLUTION:

95% of the time I have had this issue, the problem was that I removed a control, and its references in the .cs file, but forgot it in the JQuery.  So in the JQuery I was doing a .hide() on the removed control which causes the cryptic error above.  To debug I simply looked for each instance of $('#mycontrolxxxxxxx').hide(); and made sure that #mycontrolxxxxxxx actually still existed.  Sure enough, I forgot to remove a JQuery line.  Once I removed the rogue JQuery line, the issue went away. 

 

NOTES:

There are no notes on this topic.

How To Disable The Enter Key Using JQuery



TODO:

Have you ever wanted to disable the enter key for your entire form, including "modal" edit popup windows for the Telerik RadGrid?  If so, put this code in the document.ready function, and the Enter key will no longer submit your form data.

 

SOLUTION:

$(document).ready(function() {
        //disable the enter key, it causes too many issues....
        //Bind this keypress function to all of the input tags
        $('input').live('keypress', (function (evt) {
             //Deterime where our character code is coming from within the event
             var charCode = evt.charCode || evt.keyCode;
             if (charCode == 13) { //Enter key's keycode
                  return false;
             }
        }));

        //OR USE THE ONE BELOW.  ONE ABOVE WORKED BEST FOR ME
    function checkKeyPress(e) {
        if (e.keyCode == 13) {

            if (!e) var e = window.event;

            e.cancelBubble = true;
            e.returnValue = false;

            if (e.stopPropagation) {
                e.stopPropagation();
                e.preventDefault();
            }
        }
    }
    $("input").keydown(checkKeyPress);
})​

 

NOTES:

Method 1 worked for me, but I have seen method 2 used before also.

How To Secure Sharepoint Application Pages By User Group



TODO:

Have you ever wanted to secure an Sharepoint Application Page by User Group?  If so, just use the method below, and call it in Page_Load.

 

SOLUTION:

/// <summary>
/// Validate that the page can be accessed
/// </summary>
/// <returns></returns>
protected void ValidatePageAccess(string[] AllowedUserGroups)
{
     try
     {
          //get web object
          using (SPWeb currentWeb = this.Web)
          {                    
               #region Allowed Groups

               SPGroup allowedGroup = null;
               bool userHasAccess = false;

               //check each, if one group is OK, all are.
               foreach (string group in AllowedUserGroups)
               {
                   allowedGroup = currentWeb.Groups[group];

                   //see if user is in allowed group
                   if (allowedGroup.ContainsCurrentUser)
                   {
                       if (Request.HttpMethod == "POST")
                       {
                           SPUtility.ValidateFormDigest();
                       }
                       userHasAccess = true;
                       break;
                   }
               }
               
               //now check access
               if(!userHasAccess)
               {
                    throw new Exception("User does not have access");
               }
               #endregion 
          }
     }
     catch (Exception x)
     {
          Response.Redirect("/_layouts/accessdenied.aspx");
     }
}

 

NOTES:

There are no notes on this topic.

How To Fix "Team Foundation Error: Login Failure: Unknown Username or Bad Password" Error in Visual Studio



TODO:

In Visual Studio, you try to click on Security or other items, and you receive "Team Foundation Error:  Login Failure: Unknown Username or Bad Password"

 

SOLUTION:

You need to start Visual Studio as your Domain User

start -> run > runas /netonly /user:my domain\myuser "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe

 

NOTES:

There are no notes on this topic.

How To Update Items In List<T> Using LINQ



TODO:

You have a list of objects, and you want to update all items with a particular value, based off of a particular condition.

 

SOLUTION:

string newAccountNumber ="12345";
string previousAccountNumber = "54321";

foreach (var account in dsAccountList.FindAll(a => a.AccountNumber == previousAccountNumber))
{
     account.AccountNumber = newAccountNumber;
}

 

NOTES:

The example will update the account number for all accounts with AccountNumber = previousAccountNumber

Page_Load Is Called Twice



 TODO:

You have an Application Page, or regular ASPX page, .Net 3.5 and you notice that each Postback is happening twice, for no apparent reason.

 

SOLUTION:

If you have an IMG SRC="" tag, or a placeholder like IMG SRC="#" this will cause the issue.  If dynamically generating SRC values, be sure that it is actually being populated with a valid image path.

 

NOTES:

This bug has been fixed in .Net 4.0+