Archive

Archive for May, 2010

RequiredFieldValidator conditional validation via client side script

Interesting Problem.

I created a user edit page on an ASP.Net website. A user when looking at their own record got a “Change Password” panel. It is optional and only updated if data is entered in the text boxes. I wanted to use the CompareValidator to compare the txtPassword and txtConfirmPassword textboxes.

This worked great, I set up the CompareValidator to validate the txtConfirmPassword against the txtPassword. Problem is the ConfirmValidator does not fire when there is nothing entered in the txtConfirmPassword textbox. So the user could enter a password and click submit and the compare validator would not fire and the page would submit.

So I needed a RequiredFieldValidator on txtConfirmPassword but this is only needed to be enabled after some text is entered in the txtPassword text box.

I found this article:
http://www.aspdotnetfaq.com/Faq/How-to-control-ASP-NET-Validator-Controls-Client-Side-validation-from-JavaScript.aspx

and implemented this javascript. Note I am using a little jQuery to get the controls. (1.4.1)

And using this information was able to write the following script:

<script type="text/javascript">
    $(document).ready(function() {
        $('#<%=txtPassword.ClientID %>').change(function() {
            var value = $('#<%=txtPassword.ClientID %>').val();
            if(value.length > 0){
                EnableValidators(true);
            } else {
                EnableValidators(false);
            }
        });
    });

    function EnableValidators(enable)
    {
        ValidatorEnable(document.getElementById('<%=rfvConfirmPassword.ClientID%>'), enable);
    }
</script>

The interesting thing is “ValidatorEnable” is a Asp.Net function that client-side enables and disables the validators.

Nice 🙂

Categories: ASP .Net, c#

SSRS 2008 R2 repeat headers on pages

21 May, 2010 6 comments

As of SQL Server 2008 R2 the way to make headers of tablix’s repeat has changed considerably.

I suggest you read the post here:
http://blogs.msdn.com/robertbruckner/archive/2008/10/13/Repeat-Header-And-Visible-Fixed-Header-Table.aspx

In short all the documentation I found suggested you needed to turn on the “Advanced Mode”.

Advanced mode is a bit hard to find.

See the bottom of your design space you should see the heading:

  • Row Groups
  • Column Groups
  • and keep looking right and you see the innocent little black down triangle. Click that and choose advanced mode.
  • Click on the static elements and it will highlight a cell in the report, this identifies the element you are attempting to change.
    To make a heading repeat. Click on the static member for the header row/s of you tablix, view the properties pane and set these properties:

  • KeepWithGroup: After
  • RepeatOnNewPage: true
  • FixedData: true to keep headers visible
  • Categories: Reporting Services

    Remote Desktop, MSTSC /console switch no longer works

    Long ago when versions of remote desktop changes the /console switch to login to the console of a server remotely stopped working, some time around the release of the OS that shall not be named by Microsoft. (Vista).

    Anyway, I just did some digging and found all these incorrect solutions, so here it is.

    As tested on version 6.0.6001.18000 of remote desktop

    /console has changed to /admin

    works just as before.

    Cheers
    John

    Categories: OS

    SSRS SQL Server Reporting Services – How to reference an external image hosted on the report server

    7 May, 2010 1 comment

    Ok,

    I needed to do this the other day, after an hour or so I finally got it.

    Issue, I have an images directory that is deployed to the report server with my reports, It is hidden in the tile view.

    The problem, how to insert an image into my report that references the images directory hosted on my report server.

    Well after a while of struggling with it I noticed this little perl of information in the warnings for my report;

    [rsWarningFetchingExternalImages] Images with external URL references will not display if the report is published to a report server without an UnattendedExecutionAccount or the target image(s) are not enabled for anonymous access.

    So to make this work do the following

    1. Setup an unattended execution account, (See the Execution pane in the Reporting Services Configuration Tool)
    2. Ensure “everyone” has browse access to the images folder, (or confirm that the user running the report has access to the images folder)
    3. In your report set the URL of your image with an expression like the following:


    =IIf(Globals!ReportServerUrl is nothing, "http://localhost/ReportServer", Globals!ReportServerUrl) + "?%2fimages%2fimage.png"

    Two things of interest in this code:
    1. There is a ? after the http:///ReportServer path
    2. This expression uses the localhost when in the IDE preview window and the full reportserverUrl when deployed to a server. I didn’t want to hard code localhost for a production deployed report.

    And now it all works both in the IDE and the deployed report.

    Cheers

    Categories: Reporting Services

    C# Stack<T> with maximum limit

    I am writing a web based app at the moment and I am wanting to maintain a history of the persons movements around the site to enable some business logic for handling back button clicks.

    I wanted to use a Stack but I did not want to let it get too out of control in memory if people take weird navigation choices around the site. So I wanted a stack that would push on the top but have a maximum limit so that when the maximum was reached the oldest items on the stack just fell out the bottom.

    So I wrote the MaxStack. Hope you like it. It uses a generic linked list to implement the stack like interface.

    Note its also serializable as I am storing it in session.
    (Sorry about the indenting wordpress has mashed it)

    MaxStack

    using System;
    using System.Collections.Generic;

    namespace MyArchitecture
    {
    /// <summary>
    /// Generic stack implementation with a maximum limit
    /// When something is pushed on the last item is removed from the list
    /// </summary>
    [Serializable]
    public class MaxStack<T>
    {
    #region Fields

    private int _limit;
    private LinkedList<T> _list;

    #endregion

    #region Constructors

    public MaxStack(int maxSize)
    {
    _limit = maxSize;
    _list = new LinkedList<T>();

    }

    #endregion

    #region Public Stack Implementation

    public void Push(T value)
    {
    if (_list.Count == _limit)
    {
    _list.RemoveLast();
    }
    _list.AddFirst(value);
    }

    public T Pop()
    {
    if (_list.Count > 0)
    {
    T value = _list.Last.Value;
    _list.RemoveFirst();
    return value;
    }
    else
    {
    throw new InvalidOperationException("The Stack is empty");
    }

    }

    public T Peek()
    {
    if (_list.Count > 0)
    {
    T value = _list.First.Value;
    return value;
    }
    else
    {
    throw new InvalidOperationException("The Stack is empty");
    }

    }

    public void Clear()
    {
    _list.Clear();

    }

    public int Count
    {
    get { return _list.Count; }
    }

    /// <summary>
    /// Checks if the top object on the stack matches the value passed in
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    public bool IsTop(T value)
    {
    bool result = false;
    if (this.Count > 0)
    {
    result = Peek().Equals(value);
    }
    return result;
    }

    public bool Contains(T value)
    {
    bool result = false;
    if (this.Count > 0)
    {
    result = _list.Contains(value);
    }
    return result;
    }

    #endregion

    }
    }

    Categories: c#

    SQL Server 2008 R2 Nov CTP – Uninstall issues

    5 May, 2010 4 comments

    I was attempting to uninstall the SQL Server 2008 R2 Nov CTP and I found the SQL server 2008 R2 (x64 in my case) uninstaller and everything appeared to go to plan, but….

    When it had finished uninstalling the Icon still appeared in my list of things to uninstall. So I attempted to uninstall again and chose everything that was there and uninstalled that. Again it told me success but the icon remained.

    So next I thought I will just uninstall all the other 2008 R2 items in the list, starting with something like native client, and it told me:

    Warning 26002: The following products on SQL Server 2008 Native Client
    – SQL Server 2008 R2 Database Engine Shared
    – SQL Server 2008 R2 Common Files

    I understand dependencies, so I thought fine, I will just uninstall in reverse order of precedence until I could succesfully uninstall everything. The stupid thing was I could not find these items in the list of software installed on my computer.

    Firstly note the name, is not Microsoft SQL Server … so check down your list of items to see if it is not just listed at the bottom of the page in the “S” section not in “M” where all the other Microsoft SQL Server entries are.. (grrrr <– angry @ microsoft sound).

    So if you still cant find it do this, go to this registry key
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

    Assume I was looking to unintall the "SQL Server 2008 R2 Database Engine Shared",

    • Search for SQL Server 2008 keys in the uninstall registry.
    • Keep searching until you find the Database engine shared install location
    • Note the “Install source”, copy the path and access that path via Start :: Run
    • Luckily I still had the install media on my machine, (it was in my downloads directory), and opening the path showed a directory with the .msi file. If you are not as lucky as me you will need to find the installation media and go to this relative path location
    • Right click on the msi and choose uninstall
    • This threw a little error,which I ignored and it then proceeded to successfully uninstall the item

      Repeat this process until you have successfully uninstalled all the items, that it is complaining about and then go back and start uninstalling from the uninstall UI those other SQL Server 2008 R2 files.

      Cheers

    Categories: SQL Server, Uncategorized

    SQL Server 2008 Uninstall – Restart Computer Failure

    5 May, 2010 2 comments

    Sometimes when attempting to uninstall SQL Server, “Setup Support Rules” performs a check and fails on “Restart Computer” with the following error;

    “A computer restart is required. You must restart this computer before installing SQL Server”

    So you restart your computer and try again, same error… Doh!

    So now it turns out there is a bad registry entry, so if you have restarted your computer and there are actually no pending restart operations that you are aware of the do the following

    1. Leave the Setup Support Rules UI open if you are already in there
    2. Open Regedit
    3. Go to the following registry key”HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager”
    4. Delete the “PendingFileRenameOperations”
    5. Click “Re-Run” in Setup Support Rules launch the uninstall again

    So now you will have passed the restart computer check and you can continue and get rid of that pesky old version of SQL Server.

    Categories: SQL Server, Uncategorized