Archive

Archive for May, 2010

RequiredFieldValidator conditional validation via client side script

May 27th, 2010 No comments

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 🙂

VN:F [1.9.22_1171]
Rating: 9.0/10 (1 vote cast)

Categories: ASP .Net, c# Tags:

SSRS 2008 R2 repeat headers on pages

May 21st, 2010 10 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:

  • FixedData: true (to keep headers visible when scrolling)
  • KeepWithGroup: After
  • RepeatOnNewPage: true
  • Edit – Nov 2011
    So its been a year or so since I wrote this and in a case of dog fooding, I had to fix up a report and I hit the same error as listed by nes, itch and Terrence below.

    Here is what the header Row Groups looked like in my report.

    Each one of the static rows between “table1_eventId” and “rsvp” are rows in a group header in the report. When you click on the static row, the element in the report is highlighted

    So I followed my own instructions and setup the row group properties on the static row immediately above rsvp as per my instructions, ran the report and got a similar error to Terrence.

    Delving into the issue there are two possible solutions:
    Solution 1
    Assuming that you need all the header rows to repeat on each page, then you need to configure EVERY static row in the row groups in the same way, (every row between table1_EventId and Rsvp). Get one of the properties different and you get that error.

    Solution 2
    Assuming you don’t need the entire section above to repeat on every page. I needed to only have the table header row repeat. (the last static row prior to RSVP contained the details of the table column headers).
    I right-clicked on the RSVP row Group, chose Insert Row –> outside Group – Above. This inserted a single blank row. Copy the header columns from the row that is now in the outer group, and paste into the new row that appeard. Delete the previous header row. Now follow the instructions above. As there is only 1 row then the repeating header instructions above will work.

    Here is what the row groups looked like after solution 2. The static row between rsvp and table1_details_group is the header as highlighted and this is where you can setup the single repeat header proper

    The trick is that to have the header repeat you have to update every row at a level in the row group to have the same settings.

    VN:F [1.9.22_1171]
    Rating: 0.0/10 (0 votes cast)

    Categories: Reporting Services Tags:

    Remote Desktop, MSTSC /console switch no longer works

    May 13th, 2010 No comments

    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

    VN:F [1.9.22_1171]
    Rating: 0.0/10 (0 votes cast)

    Categories: OS Tags:

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

    May 7th, 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. ** Very Important ** Ensure “everyone” has browse access to the images folder, (or confirm that the unatteneded execution user 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

    VN:F [1.9.22_1171]
    Rating: 6.2/10 (5 votes cast)

    Categories: Reporting Services Tags:

    C# Stack with maximum limit

    May 6th, 2010 5 comments

    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.First.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;
            }
    
    	public IEnumerator GetEnumerator()
    	{
                return _list.GetEnumerator();
    	}
    
            #endregion
    
        }
    }
    
    VN:F [1.9.22_1171]
    Rating: 6.6/10 (7 votes cast)

    Categories: c# Tags:

    SQL Server 2008 R2 Nov CTP – Uninstall issues

    May 5th, 2010 7 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_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstall

    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

      VN:F [1.9.22_1171]
      Rating: 8.2/10 (5 votes cast)

    Categories: SQL Server, Uncategorized Tags:

    SQL Server 2008 Uninstall – Restart Computer Failure

    May 5th, 2010 20 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.

    VN:F [1.9.22_1171]
    Rating: 9.8/10 (13 votes cast)

    Categories: SQL Server, Uncategorized Tags: