RSS

Tag Archives: .NET

WPF Controls do not resize inside container

When you try to put a WPF User Control or a Page inside of a container you will notice the control is not resizing to the parent it is hosted in. Example, a page that is hosted in a frame.

This is due to the size you have set to the control or page.

 <Page x:Class=”LAD_Project_Planning_WPF.pProjectCard” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”  Title=”pProjectCard” Loaded=”Page_Loaded” Height=”382″ Width=”789″>
<Page.Resources>

 

As you can see the page’s height and width are set to 382 and 789 pixels. This will cause the control to always have these dimensions. It doesn’t matter if it is set to strech inside of a container or not.

Removing the dimensions from the control will solve this issue at runtime, but you won’t be able to see the control in design time.

The only solution I found until now was to change the dimensions in the OnLoad event.

if (LicenseManager.UsageMode != LicenseUsageMode.Designtime)
{
    this.Width = double.NaN; 
    this.Height = double.NaN;
}

 
1 Comment

Posted by on October 19, 2009 in .NET

 

Tags: ,

Tip: Missing a namespace?

When using classes in certain namespaces of .NET you need to include the using statement at the top of you code.
If you fail to do so the compiler won’t be able to find the class.

Example:

XmlDoc.Load(Path.GetDirectoryName(Assembly.GetAssembly(typeof(OCIForm)).CodeBase) + “SampleXMLFile.xml”);

Here the Path and Assembly classes will not be found because I haven’t included the System.IO and System.Reflection namespaces.

You can add them manually if you know by hard which namespace to use for this class. But if your memory fails you, you could simply right clich the classname and select Resolve > Using System.IO;
The using statement will be added automatically.

Resolve function in VS

Resolve function in VS

Visual studio will automatically search for the namespace. ;)

 
Leave a comment

Posted by on March 17, 2009 in .NET

 

Tags: ,

Get the current assembly path in ASP.NET

The get the current assembly’s path you could execute this code to get the current path:

Assembly.GetExecutingAssembly().Location

 

This code will return the directory where the assembly is curently located. For an ASP.NET application this will be “C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files”.

To get the path of the assembly as it is installed (ex. c:\inetpub\wwwroot\<myapp>\bin) execute this code:

 

Path.GetDirectoryName(Assembly.GetAssembly(typeof(<myclass>)).CodeBase)

 

 
Leave a comment

Posted by on February 5, 2009 in .NET

 

Tags:

Wow6432 Registry key on x64 machine

When you look at the registy of a x64 System you will notice that there are some keys in there called Wow6432Node. These keys are there for 32-bit applications.
Basically if you have a 32-bit application that is reading from the registry in the key “HKEY_LOCAL_MACHINE\SOFTWARE\<company>\<product>”
it is actually reading from “HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\<company>\<product>”.

You can turn of this behaviour in your code by using dllimport and so on. pretty complicated.  Read all about it here.
A simple work arround ofcourse is to store you registry settings in the Wow6432Node.

 
3 Comments

Posted by on February 5, 2009 in .NET

 

Tags:

ASPX extension is missing in IIS

Before you can use ASPX pages in an IIS website you need to enable this Webservice Extension in IIS.
If you install IIS after the .NET framework was installed, it is likely that the ASPX extension is not registered in IIS.

To register it manually run the aspnet_regiis.exe application in the .NET framework folder.

Replace the <framework version> with the correct verion.

c:\Microsoft.NET\FRAMEWORK\<framework version>\aspnet_regiis.exe -i

NOTE: If you are running a x64 OS you will need to configure IIS so that is will run 32-bit applications. If not, the apsnet_regiis application will not work. An error message stating “The error indicates that IIS is in 64 bit mode, while this application is a 32 bit application and thus not compatible.”

To enable to run 32-bit applications on 64-bit Windows

1. Open a command prompt and navigate to the C:\Inetpub\AdminScripts directory.
2. Type the following command:

cscript.exe adsutil.vbs set W3SVC/AppPools/Enable32BitAppOnWin64 true

3. Press ENTER.
 
Leave a comment

Posted by on February 5, 2009 in .NET

 

Tags:

Custom ASPX assemblies

Custom ASPX assemblies can now be placed in the ISV/<yourapp>/bin folder due to Update Rollup 2.

Read more about it in this post

 
Leave a comment

Posted by on February 5, 2009 in CRM 4

 

Tags: ,

Refreshing a parent window when crmForm.IsDirty

When you try to refresh the parent window from an ISV page and the crmForm was
modified but not saved, you will get a confirmation dialog from CRM asking you
to continue or cancel the action.

To disable this behaviour you can Save the CRM form before the refresh action.

This seems to be standard CRM behaviour. You can try this when modifying an
account and then deactivating it. The new values will be saved automatically and
the account will be deactivated.

Put the following code in the OnInit of the aspx page:

protected override void OnInit(EventArgs e)
{
// Check if the crmForm was modified.
Response.Write(“<script>” + “\n”);
Response.Write(“if (window.dialogArguments.document.crmForm.IsDirty == true)” + “\n”);
Response.Write(“{“ + “\n”);

Response.Write( window.dialogArguments.crmForm.Save();” + “\n”);
Response.Write(“}” + “\n”);
Response.Write(“</script>;”);

base.OnInit(e);
}

Regards,

Kenny

 
1 Comment

Posted by on February 3, 2009 in CRM 4

 

Tags: , ,

Putting a DateTime value in a CrmDateTime field

When you want to assign a DateTime value to a CrmDateTime field while using the Webservice API it is not as simple as converting the DateTime field to a string and assigning the value.

The string has to be in a specific format.

Example:
CrmDateTime sEndDate = new CrmDateTime(MyDateTimeValue.ToString());

The above will NOT work.
Format the DateTime with the following format.

CrmDateTime sEndDate = new CrmDateTime(MyDateTimeValue.ToString(“s”));

 
1 Comment

Posted by on February 3, 2009 in CRM 4

 

Tags: ,

Values of ASP.NET Controls are cleared on postback

I came accros this issues when I was trying to export a gridview that I made to excel. When I pressed my “Export To Excel” button on my custom ASPX page the gridview turned to null.

To be able to re-use data in an ASP.NET control after doing a postback, the EnableViewState property of the control and the page must be set to true.

When you create a new ASP.NET page this is the case by default. Except when you deploy this page to MS CRM 4.0 it is likely your code will not work as you excpected because MS CRM 4.0 disables the viewstate of all it’s pages in it’s web.config file.

To avoid this issue be sure to enable the viewstate in your custom page.

Example:

< %@ Page Language="C#" AutoEventWireup="true" CodeFile="MyPage.aspx.cs"    Inherits="MyPage" EnableViewState="true % >
 
Leave a comment

Posted by on February 3, 2009 in CRM 4

 

Tags: ,

 
Follow

Get every new post delivered to your Inbox.