Monday, March 23, 2009

ASP.NET textbox multiline maxlength

Very useful and simple javascript if you want to protect a multiline text box from enterting too many characters!

http://geekswithblogs.net/mahesh/archive/2007/12/27/asp.net-textbox.multiline-maxlength.aspx

function CheckCount(text,length)

 

{

 

      var maxlength = new Number(length); // Change number to your max length.

 

if(text.value.length > maxlength){

 

                text.value = text.value.substring(0,maxlength);

 

                alert(" Only " + maxlength + " characters allowed");

            }

}

<asp:TextBox ID="textBox" onKeyUp="javascript:Count(this,100);" onChange="javascript:Count(this,100);"  TextMode=MultiLine Columns="5" Rows="5" runat=server>

    </asp:TextBox>

Or something like that...

Some useful pages for OpenSocial

Just starting to look at this now...

Here's some useful OpenSocial pages I've found:

This reply is very useful with links and ideas: http://www.mail-archive.com/opensocial-api@googlegroups.com/msg04079.html

Here's the Ning hello world application: http://developer.ning.com/forum/topic/show?id=1185512:Topic:4655&page=3&commentId=1185512:Comment:87952&x=1#1185512Comment87952

The iGoogle page is very good - and I use their sandbox quite a lot! - http://code.google.com/apis/igoogle/docs/igoogledevguide.html - sandbox at http://www.google.co.uk/ig?refresh=1

(I also find it quite funny that Google has a "legacy" gadget section already! http://code.google.com/apis/gadgets/docs/legacy/gs.html#Scratchpad

Here's the developer's guide  http://code.google.com/apis/opensocial/docs/0.8/devguide.html

An example gadget (not quite opensocial) on CodeProject - http://www.codeproject.com/KB/ajax/igoogle_gadget.aspx

MySpace also has opensocial capabilities - http://developer.myspace.com/community/opensocial/helloworld.aspx (I never use MySpace - but maybe I should take a look one day)

The www.opensocial.org  site is very useful - e.g. here's a tutorial - http://wiki.opensocial.org/index.php?title=OpenSocial_Tutorial and here's a list of containers - http://wiki.opensocial.org/index.php?title=Containers

Another interesting tutorial - http://www.devx.com/webdev/Article/37952/0/page/3 (plus also see their Gadget tutorial - http://www.devx.com/webdev/Article/35007/0/page/4)

Not sure about this link - it's about xml2json - but I think there may be better ways available now - http://www.phdcc.com/xml2json.htm





Thursday, March 19, 2009

Changing YetAnotherForum to display time as "x minutes ago"

This really demonstrates the beauty of open source!

I've got a lot of international visitors to www.runsaturday.com - so I wanted to avoid time zone specific times (yes - I know YAF does let each user customise the time zone, but that doesn't really help when I get so many guests through)

So ... I decided to adopt the facebook/twitter approach - to listing times like "23 seconds ago" and "in the last week".

It was remarkable easy to change. Here's the main new code:

        /// <summary>

        /// Formats a datetime value into "friendly terms" - let's hope this works!

        /// the date is yesterday or today -- in which case it says that.

        /// </summary>

        /// <param name="o">The datetime to be formatted</param>

        /// <returns>Formatted string of DateTime object</returns>

        public string FormatDateTimeTopic(object o)

        {

            //string strDateFormat;

            DateTime dt = Convert.ToDateTime(o) +TimeOffset;

            DateTime nt = DateTime.Now+TimeOffset;

 

            TimeSpan diff = nt - dt;

            double totalSeconds = diff.TotalSeconds;

            double totalMinutes = diff.TotalMinutes;

            double totalHours = diff.TotalHours;

            double totalDays = diff.TotalDays;

 

            try

            {

                if (totalSeconds < 15.0)

                {

                    return GetText("MomentsAgo");

                }

                if (totalSeconds < 100.0)

                {

                    return string.Format(GetText("SecondsAgo"), totalSeconds);

                }

                if (totalMinutes < 100.0)

                {

                    return string.Format(GetText("MinutesAgo"), totalMinutes);

                }

                else if (totalHours < 10.0)

                {

                    return string.Format(GetText("HoursAgo"), totalHours);

                }

                else if (totalDays < 1.0)

                {

                    return GetText("InTheLastDay");

                }

                else if (totalDays < 2.0)

                {

                    return string.Format(GetText("ADayAgo"), totalDays);

                }

                else if (totalDays < 30.0)

                {

                    return string.Format(GetText("DaysAgo"), totalDays);

                }

                else

                {

                    return dt.Date.ToString("dd MMM yy");

                }

            }

            catch (Exception)

            {

                return dt.ToString("f");

            }

        }

 

Old code was:



            /// <summary>

            /// Formats a datatime value into 07.03.2003 00:00:00 except if

            /// the date is yesterday or today -- in which case it says that.

            /// </summary>

            /// <param name="o">The datetime to be formatted</param>

            /// <returns>Formatted string of DateTime object</returns>

            public string FormatDateTimeTopicOld( object o )

            {

                  string strDateFormat;

                  DateTime dt = Convert.ToDateTime( o ) + TimeOffset;

                  DateTime nt = DateTime.Now + TimeOffset;

 

                  try

                  {

                        if ( dt.Date == nt.Date )

                        {

                              // today

                              strDateFormat = String.Format( GetText( "TodayAt" ), dt );

                        }

                        else if ( dt.Date == nt.AddDays( -1 ).Date )

                        {

                              // yesterday

                              strDateFormat = String.Format( GetText( "YesterdayAt" ), dt );

                        }

                        else if ( BoardSettings.DateFormatFromLanguage )

                        {

                              strDateFormat = dt.ToString( GetText( "FORMAT_DATE_TIME_SHORT" ) );

                        }

                        else

                        {

                              strDateFormat = String.Format( "{0:f}", dt );

                        }

                        return strDateFormat;

                  }

                  catch ( Exception )

                  {

                        return dt.ToString( "f" );

                  }

            }

 

Connecting to SQL Server Express remotely

I'm beginning to become more of a power user....

The section below is copied from http://www.datamasker.com/SSE2005_NetworkCfg.htm (just copying it in case the original disappears)

Although by the time I become a proper power user I'll hopefully be on the full monty - not the express!

Here's the instructions:

Here's a quick summary of the actions you need to take. The first three actions have a separate page which provides more details and some screen shots of the procedure.

  1. [Link] Enable the TCP/IP protocol using the Surface Area Configuration Utility
  2. [Link] Make sure the TCP/IP protocol is enabled in the SQL Server Configuration Utility
  3. [Link] Make sure the SQL Server browser is started. Note this step is optional. It is possible to set the SQL Server instance to use a fixed IP address - but this is non-standard for named instances. See sqlexpress's WebLog for details.
  4. Make sure SQL Server and SQL Server Browser are exempted by the firewall on the server machine. This is done by putting sqlservr.exe and sqlbrowser.exe as an exception in the windows firewall. Chris D. sent in a note which might help.
  5. Note: In order to get things to work. You might need to completely reboot the server machine after making the changes. There have been reports (thanks P.C.) that starting and stopping the SQL Server and Browser software is not enough.

Monday, March 16, 2009

Essential reading if you are trying to run DNN5 with a proper SQL Server Express Connection String...

This blog post has just saved me lots of horrible experimentation

http://www.dotnetnuke.com/Community/Blogs/tabid/825/EntryId/1202/DNN-SQLExpress-SQL-Server-Management-Studio.aspx

Basically I've been running using "File" access - and now it's definitely time to move up to "proper" access. For a start it will make my backup process 100 times easier :)

Post is reproduced here - just so it can go missing in any reorg at DNN:

Recently I rebuilt my laptop and decided to only install SQL Express and not the full SQL Server 2005.  The issue I can across occurs when you attach to the DNN mdb file within SQL Server Management Studio.  Once you have done that the connection string does now work and you DNN site cannot connect to the database. And no matter what you do you cannot correct it even by detaching it, restart SQL Express, resetting IIS, etc.  I finally had to scrap the database and do it all again.  Below is the way to setup DNN and SQL Express if you want to also access the database from within SQL Server Management Studio.

1) Rename the Database.mdb to another name.  (This is optional).

2) Open SQL Server Management Studio and do the following 
  • Attach the database 
  1. Right click on the database folder and choose attach.
  2. Click Add button and point to the database you want to attach to.
  3. Click on the "Attach As" column and give it a more friendly name.  For this blog purpose we will change it to DotNetNuke_ModDev
  4. In the lower screen delete the line that references the ".ldf" file.  This will be created and you will get an error that it cannot be found if you do not delete it.
  5. Click on the "Current File Path" for the ".mdf" file and update it so it points to the location of the DNN database you are attaching to.
  6. Click Okay and the database should be attached correctly.
  • Set up permissions
    • Adding Login
      1. Click on the security\logins folder.
      2. If the ASPNet user exist you can skip this section.
      3. Right click login folder and choose "New Login"
      4. Click the "Search" button, then the "Advance" button, and then the "Find Now".  This will bring up a list of user on the computer and select the ASPNet account.
      5. Make sure Windows authentication is checked and click "OK" to add user.
    •  Adding Database User
      1. Click on "Databases\Security\Users folder.
      2. If the ASP.Net user exist you can skip this section
      3. Right click the user folder and choose "New User"
      4. Click on the "..." button next to the Login Name, then click on the "Browse" button.
      5. Check the ASPNet user and click "OK" button.  Click the OK button on the Select Login screen and this will add the user.
      6. Under database role membership check one of the following combinations.  Option #2 is more secure.  Click "OK" button when done.
        • Permission Options #1
          • dbowner
        • Permission Options #2
          • db_datareader
          • db_datewriter
          • db_ddladmin
          • db_securityadmin
    • Setting Database Permissions (Only needed it Option #2 is chosen above)
      1. Right click on the database you attached to and choose "Properties"
      2. Click on "Permissions" under select a page (upper-left of screen).
      3. Under Explicit permission for {Database Name}, make sure that the Grant box is checked for Execute.
3) Update the connection strings in the DNN web.config file.  Do not forget to use the same connection string in the <ConnectionString> and <AppSettings> section.

FROM
Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|Database.mdf;

TO

Data Source=.\SQLExpress;Integrated Security=True;User Instance=False;Database=DotNetNuke_ModDev;

4) Access the DNN web site to run the installation process.

You should now have a working DNN site and a SQL Express database that you can access/manipulate using SQL Server Management Studio and still be able to access it from the web site as well.

Validation of viewstate MAC failed / The state information is invalid for this page and might be corrupted

I'm hitting some of these problems on runsaturday at the moment.

These definitely aren't being caused by machinekey errors - this is occurring on a single PC.

Some of these might be occurring due to some specific DotNetNuke behaviour - especially when the page makeup changes during a postback.

However, in one particular case - I have one specific Mac user who (regardless of whether he uses Firefox or Safari) just occasionally seems to randomly hit one of these problems).

This has me quite stumped.... but I'm still looking :)

Here's one discussion that seems to be particularly relevant - http://forums.asp.net/t/955145.aspx?PageIndex=4

Wednesday, March 04, 2009

Still trying to understand IIS7....

This excellent post has at least solved one of my queries - I simply could not understand why IIS7 didn't let me select .NET 3.5 - the answer is in the runtime... http://www.west-wind.com/Weblog/posts/289139.aspx

Tuesday, March 03, 2009

Problems using ThreeSharp with bucket names containing DOTs

I'm trying to set up a bucket name at the moment (for public access) and keep hitting:

The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel

One solution seems to be not to include "config.Format = CallingFormat.SUBDOMAIN;" - but this obviously won't help people with European buckets.

Sunday, March 01, 2009

Azure downtime report

Using host-tracker to check my Azure sites.

Here are the stats from Feb - I think all downtime must be from Azure itself - I haven't taken the site down at any point.

I can also get a response time report if anyone is interested

Stuart

Stacka
  http://www.stacka.com
   Total uptime:99.71% Downtime:2 hour(s) 13 min(s)
       Monthly uptime:99.75% Downtime:1 hour(s) 39 min(s)
           Day 2009-02-28 Uptime:100.00%
           Day 2009-02-27 Uptime:100.00%
           Day 2009-02-26 Uptime:100.00%
           Day 2009-02-25 Uptime:100.00%
           Day 2009-02-24 Uptime:96.00% Downtime:57 min(s) 37 sec(s)
           Day 2009-02-23 Uptime:100.00%
           Day 2009-02-22 Uptime:100.00%
           Day 2009-02-21 Uptime:100.00%
           Day 2009-02-20 Uptime:97.12% Downtime:41 min(s) 30 sec(s)
           Day 2009-02-19 Uptime:99.95% Downtime:41 sec(s)
           Day 2009-02-18 Uptime:100.00%
           Day 2009-02-17 Uptime:100.00%
           Day 2009-02-16 Uptime:100.00%
           Day 2009-02-15 Uptime:100.00%
           Day 2009-02-14 Uptime:100.00%
           Day 2009-02-13 Uptime:100.00%
           Day 2009-02-12 Uptime:100.00%
           Day 2009-02-11 Uptime:100.00%
           Day 2009-02-10 Uptime:100.00%
           Day 2009-02-09 Uptime:100.00%
           Day 2009-02-08 Uptime:100.00%
           Day 2009-02-07 Uptime:100.00%
           Day 2009-02-06 Uptime:100.00%
           Day 2009-02-05 Uptime:100.00%
           Day 2009-02-04 Uptime:100.00%
           Day 2009-02-03 Uptime:100.00%
           Day 2009-02-02 Uptime:100.00%
           Day 2009-02-01 Uptime:100.00%

clouddotnet
  http://www.clouddotnet.com
   Total uptime:98.83% Downtime:8 hour(s) 54 min(s)
       Monthly uptime:99.86% Downtime:55 min(s) 44 sec(s)
           Day 2009-02-28 Uptime:100.00%
           Day 2009-02-27 Uptime:100.00%
           Day 2009-02-26 Uptime:100.00%
           Day 2009-02-25 Uptime:100.00%
           Day 2009-02-24 Uptime:98.23% Downtime:25 min(s) 29 sec(s)
           Day 2009-02-23 Uptime:100.00%
           Day 2009-02-22 Uptime:100.00%
           Day 2009-02-21 Uptime:100.00%
           Day 2009-02-20 Uptime:98.08% Downtime:27 min(s) 43 sec(s)
           Day 2009-02-19 Uptime:99.82% Downtime:2 min(s) 32 sec(s)
           Day 2009-02-18 Uptime:100.00%
           Day 2009-02-17 Uptime:100.00%
           Day 2009-02-16 Uptime:100.00%
           Day 2009-02-15 Uptime:100.00%
           Day 2009-02-14 Uptime:100.00%
           Day 2009-02-13 Uptime:100.00%
           Day 2009-02-12 Uptime:100.00%
           Day 2009-02-11 Uptime:100.00%
           Day 2009-02-10 Uptime:100.00%
           Day 2009-02-09 Uptime:100.00%
           Day 2009-02-08 Uptime:100.00%
           Day 2009-02-07 Uptime:100.00%
           Day 2009-02-06 Uptime:100.00%
           Day 2009-02-05 Uptime:100.00%
           Day 2009-02-04 Uptime:100.00%
           Day 2009-02-03 Uptime:100.00%
           Day 2009-02-02 Uptime:100.00%
           Day 2009-02-01 Uptime:100.00%