Thursday, October 04, 2012

Ajax Control Toolkit Masked Edit Extender

Masked Edit Extender

I had a need to use the Masked Edit Extender to limit the number of decimals entered by the user on a Form. It worked great except that I could not get the value of the TextBox that I targeted the extender on the client side. I was only able to get the masked value.

I searched the web and could not find a solution. I ended up writing my own Javscript function to unmask it. It may not be perfect, but works for me. I hope this helps someone.








Formatting Numbers for decimals

Javascript: We can use Number.toFixed(x) to format any number for "x" number of trailing decimals in Javascript In .NET we can use the String Formatting while Databinding the element. See example below for GridView.

Monday, August 27, 2012

Disable Postback using Javascript



'asp:button onclick="btn1_Click" onclientclick="return VerifyCondition(this);" runat="server" tabindex="1" text="Sample Button"'>;

function VerifyCondition()
{ var xxdropdown = document.getElementById('<%= ddlXX.ClientID %>');
  var selectedxx = xxdropdown.value;
   if (selectedxx == '0')
   { alert("Please select a value before proceeding.");
     return false;
  }
 else
 {
     return true;
 }
}

Wednesday, July 25, 2012

SharePoint's Hidden User List

This morning I got a weird HelpDesk request. A user's first name was incorrectly put in Active Directory. The user logged in to SharePoint which used Windows Authentication. Everything was good except that the User, ofcourse noticed his name spelled wrong and notified helpdesk to fix it.

It was fixed in Active Directory but was not pulling over to SharePoint side. The first spot I checked was User Profiles...but fixing it here had no effect...deleted the user profile and synced it back up...no effect....

Then I stumbled upon this post which shed light on what was happening.


http://zimmergren.net/technical/sharepoints-hidden-user-list-user-information-list

So, this is what I did to fix the issue, basically browsed to our User Listing by typing /_catalogs/users/simple.aspx from our SharePoint site...found the user in question and deleted the user from the site collection, which removed the user from all the security groups he belonged to earlier, which is cool.

Finally adding him back to the required security groups got him in with his name spelled correctly.

Wednesday, May 30, 2012

Disable Mouse Wheel Zoom

Visual Studio 2010 started behaving weird suddenly. It would zoom the text when using the mouse wheel. Could'nt find the option to disable it. Stumbled across this article and now I know that pressing Ctrl disables it.

http://visualstudiogallery.msdn.microsoft.com/d088791c-150a-4834-8f28-462696a82bb8/ Pressing Ctrl followed by mouse wheel move enables it in the IDE.​

WCF Timeout Issues

When I first converted my SharePoint Webpart to use the locally deployed WCF service, no compile errors occured.

However, when I deployed the webpart and started testing, timeouts were occuring and the page was not responding.

Researched this and found the following information useful.​ http://stackoverflow.com/questions/981475/wcf-timeout-exception-detailed-investigation

This is what I did:

1)On the Sharepoint Web.config file on my development server: Set the following: maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" Also, in the clientcode(webpart code) did the following:

2) Set the following in In Page_load: //This says how many outgoing connection you can make to a single endpoint. Default Value is 2 System.Net.ServicePointManager.DefaultConnectionLimit = 200;

3)Made sure all the WCF client objects are closed in a finally block after the WCF calls are made. Even in cases where Channels were used, closed the channel in the finally after the WCF service call was made.
The close channel has the following code where _wcfAccess is the channel created.

if (_wcfAccess != null) { ((IClientChannel)_wcfAccess).Close(); ((IDisposable)_wcfAccess).Dispose(); _wcfAccess = null; }

Inspite of having all the above in place, I ran in to an issue where my web page froze up for an indefinite period of time.The page had a call to a WCF service that should return a record. I saw the "Server too busy" exception in the diagnostics log when the above happened.

I researched and stumbled on this thread. http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/745b95d2-1480-4618-89f5-1339d6ee228d/ I was going to try the above, when I found out the below. It turns out that there was a bug in the Database code that it was returning multiple records or a Dataset instead of one record.

The WCF call then took forever to finish receiving this and the Receive Timeout on the Binding Element for the WCF contract in question was set to 10 minutes(by default) and so the page froze up for this long.

Ajax Update Panel and Required Field Validators

Ran in to an issue this morning, where the cancel button's causesvalidation="false" property was not functioning correctly.

Basically the whole page froze up if the validation failed. This(validator) was inside a formView inside an Update Panel on a Sharepoint WebPart. Researched and found this, which gave me pointers to try.

http://www.codeproject.com/KB/ajax/UpdatePanel_Validation.aspx

Finally, adding EnableClientScript="false" to the Required Field validator made the cancel button work properly.​

Enable Debugging in SharePoint

In WSS 3.0/MOSS 2007 to enable debug information we have to modify only the web.config related to your web application.

Instead, in SharePoint 2010, we have to modify two different web.config files:

1.the one that you can find in the root directory of the web application in which you want to debug you customizations (the file at the path: [drive]:\inetpub\wwwroot\wss\virtualdirectories\[port])

  2.the one that you can find into the "LAYOUTS" directory under the SharePoint root (the file at the path: [drive]:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS)

What remains unchanged from the previous version of SharePoint are the number of attribute to change in the web.config file:

•The "debug" attribute of the "compilation" element has to be set to "true"
•The "callstack" attribute of the "safemode" element has to be set to "true"
•The "mode" attribute of the "customerrors" element has to be set to "off"

This is from this site: http://www.dev4side.com/community/blog/2010/8/16/how-to-enable-debug-information-over-exceptions-on-sharepoint-2010.aspx

Enable SessionState in Sharepoint

1) Open SharePoint 2010 Management Shell (As Administrator) and type the following command:

Enable-SPSessionStateService –DefaultProvision.

2) To resolve the error and to enable session state for SharePoint there are two entries that need to exist in the web.config file.

The first is to ensure that enableSessionState is set to TRUE.

...<..pages enableSessionState="true" enableViewState="true" enableViewStateMac="true" validateRequest="false" pageParserFilterType="Microsoft.SharePoint.ApplicationRuntime.SPPageParserFilter, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" asyncTimeout="7"..>..

The second is to ensure that the remove and add lines exist in the modules section for Session.

..<..modules runAllManagedModulesForAllRequests="true"..>.. …
.<.remove name="Session" ./>. .<.add name="Session" type="System.Web.SessionState.SessionStateModule" preCondition="" ./>. … modules>

ALSO,Additional steps to ensure the "web.config"
1.Add to the configuration/system.webServer/modules element.
2.Set the enableSessionState attribute of the configuration/system.web/pages element to true.
3.Add to the configuration/system.web element


3) Reset IIS.

Enable Diagnostics in WCF service

Add these entries to the web.config file of the WCF service site(application) in question.




Consume the service. After the operation is complete or errors out, open the log file at the above specified location on the machine hosting the service to see the issue.

]] Comment this section when not in use to make sure it does not affect performance.

Also, make sure you set the includeExceptionDetailInFaults attribute to true in the WCF config file to see the root error.

Javascript Error

http://sympmarc.com/2010/08/28/how-to-fix-sys-argumenttypeexception-object-of-type-sys-_application-cannot-be-converted-to-type-sys-_application-error/​

Microsoft JScript runtime error: Object expected

It turns out I was missing a curly brace in Javascript. This post saved me lots of time. http://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/eede0ba6-1e1d-4248-98bb-6383839dfac7/​

Raising Javascript Event in ASP.NET user control

Raising Javascript Event in ASP.NET user control http://stackoverflow.com/questions/389450/raising-javascript-events-in-asp-net-user-control Server Side Method() { Server side code... this.Controls.Add(new LiteralControl("")); } This will execute the server side code​ and print the document next. We can even call this at the beginning/end of Page_load or after some server code is executed.

WCF Service Troubleshooting

WCF Service Troubleshooting tips

http://www.infosysblogs.com/microoft/2009/06/troubleshooting_wcf_service_ap.html

http://msdn.microsoft.com/en-us/library/ms731055.aspx

http://stackoverflow.com/questions/399847/net-memory-profiling-tools

Thursday, March 29, 2012

Assigning Guids to variables in C#

Assigning Guids to variables in C#

Guid invt_id = new Guid("abcd-efg-etc.....Any Guid String");
Guid invt_id = Guid.Empty;

Wednesday, March 14, 2012

Preventing GridView from reacting to enter button

function disableEnterKey(e)
{
if(e.keyCode == 13)
e.returnValue=false;
e.Cancel=true;
}



asp:GridView ID="grdView1" runat="server"
onkeydown="javascript:disableEnterKey(window.event);"


http://stackoverflow.com/questions/152099/i-want-to-prevent-asp-net-gridview-from-reacting-to-the-enter-button1​

Making a TextBox ReadOnly

Making a TextBox ReadOnly

asp:textbox id="txtItemTotal_Edit" class="TextBoxReadOnlyStyle" text="abcd" enabled="false" enableviewstate="true">' runat="server"> /asp:textbox


If you want your TextBox to behave like a label but need the values retained during a postback i.e, in ViewState then using Enabled="false" and EnableViewState="true" attributes, is one way to do it. You can apply any desirable style to your textbox using css.

Enable Diagnostics on Sharepoint Server

To Get IIS Logs:

1.Go to IISManager->Sites->Look at Site InQuestion->Note the ID of the site.
2.Click on the Site->Feature View->Logging->Note the Directory Path
3.Run your issue.
4.Browse to the Logging Directory and locate the File that ends with the ID of the site and grab It.
To Enable Diagnostics on Sharepoint Server:

1.Go to Central Admin->Monitoring->Reporting->Configure Diagnostic Logging
2.Select All Categories, Set the level to Verbose; and note the Log Path
3.Go to Servics.msc and Restart Sharepoint 2010 Tracing service
4.Run your issue
5.Browse to the log file path and locate your needed log file.
To disable Diagnostics on the server:(Run this in Powershell)

stsadm -o setlogginglevel -default

Enable Scripting on your browser

To allow all Web sites in the Internet zone to run scripts, use the steps that apply to your browser:


Windows Internet Explorer
(all versions except Pocket Internet Explorer)



Note To allow scripting on this Web site only, and to leave scripting disabled in the Internet zone, add this Web site to the Trusted sites zone.

1.On the Tools menu, click Internet Options, and then click the Security tab.
2.Click the Internet zone.
3.If you do not have to customize your Internet security settings, click Default Level. Then do step 4
If you have to customize your Internet security settings, follow these steps:
a. Click Custom Level.
b. In the Security Settings – Internet Zone dialog box, click Enable for Active Scripting in the Scripting section.
4.Click the Back button to return to the previous page, and then click the Refresh button to run scripts.
Got this from http://support.microsoft.com/gp/howtoscript

Get Sharepoint List GUID from Browser

Go to Information Management section in the List Settings and the URL will have the decoded list GUID.

SharePoint Exception: No item exists [url]. It may have been deleted or renamed by another user

By changing the querystring key from id to someother key named like "sid" or "pid" or anything other than "id" made the error go away.

Signing an assembly

http://msdn.microsoft.com/en-us/library/6f05ezxy(v=VS.71).aspx



To create a key pair
•At the command prompt, type the following command:
sn –k
In this command, file name is the name of the output file containing the key pair.
The following example creates a key pair called sgKey.snk.

Copy
sn -k sgKey.snk
If you are using an IDE, such as Visual Studio .NET, to sign an assembly with a strong name, you must understand where the IDE looks for the key file.
For example, Visual Basic .NET looks for the key file in the directory containing the Visual Studio Solution, whereas the C# compiler looks for the key file
in the directory containing the binary. Put the key file in the appropriate project directory and set the file attribute as follows:

VB

[C#][assembly: AssemblyKeyFileAttribute(@"..\..\key.snk")]

Thursday, February 16, 2012

Calling Javscript from code-behind

We can call javascript alert messages from code-behind(on say button_click event etc..) as below:

//Display success message (several ways) shown here
//Method 1
string st = "script language='javascript'" + "window.alert('CustomerId' :" + CustId + " deleted successfully)" + "/script";
Page.ClientScript.RegisterClientScriptBlock(GetType(),"del_successMessage", st, false);


//Method 2
//Here the Javascript function is written normally in the script tag in the Head section of the HTML page.
Page.ClientScript.RegisterStartupScript(GetType(),"Javascript", "javascript: fnShowSuccessMessage();",true);


//Both the above methods do not work if we use Update Panel as a container..see solution that works below.

System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@"script language='javascript'");
sb.Append(@"alert('CustomerId :" + CustId + " deleted successfully');");
sb.Append(@"/script");
ScriptManager.RegisterStartupScript(btnDelete, GetType(), "MyJavaScript", sb.ToString(), false);
I had to remove tags on the script tag in order to post it.

To Check if the dropdownlist has a given value before selecting it

To Check if the dropdownlist has a given value before selecting it:

ListItem li = ddlItems.Items.FindByValue(MyNr.ToString());
if (li != null) //Item Found in dropdown..so select it and display details
{
//Value was found
}
else
{ //not found }