Style Sheet Expressions

A quick note: In Internet Explorer, you can dynamically define css properties via expressions. I believe that this is unsupported in other browsers; you are probably best off trying to dynamically set css properties via separate JavaScript.

Example Style Sheet Expression:
<div style="height: expression(document.body.clientHeight /2);">

MOSS: Security Notes

When I set up SharePoint, I normally create a few groups before setting up service accounts / users. This way, when the required accounts, I only need to add them to specific AD groups, as opposed to logging on to relevant boxes to grant local admin rights / sql permissions.

The groups I create are as follows:

  • SQLSecurityAdminCreators – A group that is granted the security admin and db creator rights on the sql instance. The setup, farm admins and sql service accounts are added to this group. 
  • SPServerAdmins – A group that has local admin rights on the sharepoint boxes.
  • SPFarmAdmins – Used for central admin / default content access etc. Note – this group actually gets added to the above two groups, and is not issue with any additional perms. This group is just for easier maintenance of  SPFarm accounts.

I also normally create an Organisational Unit in AD named MOSSAccounts to contain all of these users and groups.

Note that this link is the proper way to add accounts, and you should follow this as closely as possible on production environments.

http://technet.microsoft.com/en-us/library/cc263445.aspx

Sidenote:

Note that when installing SQL, it should be on a separate box to the DC. As SQL is normally installed from an account that has local administrators rights, but a DC does not have a local administrators group – the way around this would be to install SQL as a Domain Admin – which is not good practice.

ASP.NET Controls: ClientID

If you are using a control hierarchy that implements INamingContainer, when the controls render to a browser the ID property (viewed from the html source) will not be the same as the ID you have set programatically (by doing myControl.ID, the ID will be prefixed). To overcome this, you can access the clientid property of a webcontrol (which gives you the id of a control as rendered to the browser).

Note that the clientid will not be correct if you try to obtain it before the control is added to the controls hierarchy.

See the following article for more details http://blog.steeleprice.net/archive/2004/04/12/209.aspx

Asp.net 1.0 / 1.1: Enter key for multiple forms

In asp.net 1.0 and 1.1, there seems to be no easy way of having multiple forms on a webpage that each perform separate actions when you press the enter button from within them (instead of clicking a button to postback to the server). If you press enter anywhere, the click event for the first button added to the form is run. In standard html, this would easily be accomplished by having two separate forms, however you cannot have two separate forms in asp.net.

Note that this is solved by dividing the form up with panels and specifying the defaultbutton attribute for each panel in .net 2.0

To solve this, I added some js to the onkeydown event on my textbox on my second form. Note that this works with both firefox and i.e. (hence event.which and event.keyCode).

myTextBox.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('"+ myButton.UniqueID + "').click();return false;} } else {return true}; ");

Some related articles are as follows:
http://www.codeproject.com/useritems/FormPanel.asp
http://www.dotnet247.com/247reference/msgs/5/26773.aspx
http://www.codeproject.com/useritems/aspnet_Enter_key_problem.asp
http://www.jimzimmerman.com/blog/CommentView,guid,dfa0280f-a20e-4c47-8b39-bf7cb83e3849.aspx

Nant: Building and deploying cab files

It appears that there is no nant / nantcontrib task to create CAB files (ie build .vdproj projects). Nant seems to only be capable of handling C#, VB.NET and C++ projects. To overcome this, you need to call out to devenv.exe passing in parameters as follows (assuming you have visual studio installed on your nant server). The sample below only builds the specified project and its dependencies (not the entire solution). Note that the structure of arguments passed in my example could be improved.

<target name="buildcab" depends="build" description="builds the webpart cab files">
    <exec program="C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\DevEnv.exe">
        <arg line="/build release /project myprojectname ${Build.OutputFolder}Codemy.solution.sln"  />
    </exec>
</target>

As a site note, I am installing these cabs into the Sharepoint Webpart gallery by using the following nant task (which calls stsadm):

<target name="installwebparts" depends="buildcab" description="installs the webpart cab files">
    <exec program="C:Program FilesCommon FilesMicrosoft Sharedweb server extensions60BINstsadm.exe">
        <arg line="-o addwppack -filename ${Build.OutputFolder}CodeMyProjectNamereleasesmyprojectname.CAB -force -globalinstall" />
    </exec>
</target>

C# 2.0: Dynamically Adding Controls To A Web Page

Quick note: I have just learnt a more elegant way to dynamically add controls to a webpage and then access then via events etc. See code below. Note that most crucial part of this is the call to the FindControl (part of the page NamingContainer).

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Init(object sender, EventArgs e)
    {
        TextBox c = new TextBox();
        c.ID = "txtUserName";
        c.Text = "Arse, feck, drink";
        c.Visible = true;
        form1.Controls.Add(c);
    }
    protected void Page_PreRender(object sender, EventArgs e)
    {
        try
        {
            TextBox c = (TextBox)FindControl("txtUserName");
            Response.Write(c.Text);
        }
        catch
        {
            Response.Write("There was an error");
        }
    }
}