Jan
0

IIS and redirecting a page with a Query String

Microsoft has added to the redirect function in IIS to allow for Query Strings.

Example:
In the Redirect to box, enter the domain you wish to move to (no trailing slash), plus $S$Q – for example, http://www.tek-works.com$S$Q

What does this $S$Q do? These are tags that IIS will automatically replace – $S will be replaced with the subdirectory location (such as /shopping/cart.aspx) and $Q will be replaced with the querystring (such as ?id=Blue).

$P Passes parameters that were passed to the URL to the new URL. If the request contains parameters such as http://www.oldsite.com/cart.asp?id=Blue , then $P would represent all the values after the question mark in the URL, example $P would equal id=Blue (no question mark).

$Q Passes the parameters including the question mark. This is the same as $P but includes the question mark or query string. So $P would equal ?id=Blue

$S Passes the matching suffix of the URL to the new URL. If the request is for http://www.oldsite.com/shopping/cart.asp, then $S represents /cart.asp. If the request was for http://www.oldsite.com/shopping then the value of $S would be /shopping

$V Removes the server name from the original request. If the request is for http://www.oldsite.com/shopping/cart.asp then $V would contain everything after the server name, eg: /shopping/cart.asp.

* Wildcard symbol used for replacement. Let’s say you want to redirect all requests for html pages to a single asp page – you could do so in the following way: *;*.htm;page.asp

Jan
0

What if SQL DataSource returns null or nothing

I had a SQLDataSource and wanted to show a message that nothing matches the search if the source didn’t return any rows of data.

here’s how..
add to the sqldatasource


<asp:SqlDataSource ID="SqlDataSource1" OnSelected="SqlDataSource1_Selected" ...

and then in the code behind.


Protected Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs)
        If e.AffectedRows < 1 Then
            lblnonefound.Text = "No matches found, Please try again"
            lblnonefound.Visible = True
        Else
            lblnonefound.Text = ""
            lblnonefound.Visible = False
        End If
    End Sub
Jan
0

Adding List All to a Drop Down List

I had a dropdownlist that listed all the states, when a state was chosen the SQLDataSource would return the data that matched the states column like this:


SelectCommand="SELECT [saltFirmName], [Fullname], [EmailAddy], [States] FROM [PKF NAN - SALTExperts] WHERE ([States] LIKE '%' + @States + '%')">

Problem was when I added a List All to the dropdownlist, where I wanted to list all the data about all states. This was easily done with an If statement in the code behind stating that if the selectedvalue of the DDL was “all” then the selectedvalue was now equal to “”. But it didn’t work, I finally found that you needed to add ConvertEmptyStringToNull=”false” to the ControlParameter.


<asp:ControlParameter ControlID="somecontrol" Name="States" DefaultValue="" ConvertEmptyStringToNull="false" PropertyName="selectedvalue"
Dec
0

Add Item to DropDownList w/ DataSource

If you’re having problems adding an item to a dropdownlist because that ddl has a Datasource then this should work.

You need to set AppendDataBoundItems=”true” to add items to a datasource bound DropDownlist.


<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource1"DataTextField="Short_Name" DataValueField="Short_Name" Width="150px" AppendDataBoundItems="true" >

<asp:ListItem Value="" Selected="True">Select an item</asp:ListItem>

</asp:DropDownList>
Dec
0

A Day of Array

I knew today’s online app would be a pain, because I more/less learned .net from playing around there are many things that I’ve skipped because I haven’t needed them. Array’s is one of those things, I know their a huge part of working with data but so far I’ve only had to read them, loop through them and send the data to the screen. Today changes that..

Today’s App had a few hurdles to jump over including:

  • Pull a list of states from a SQL table each in the form of NC, SC, NY each record having different amounts of states.
  • List each state only once in a drop down box which means separating all the states and then converting the state abbreviation to the state name.
  • Sort the stares in alphabetical order

Pulling the data from the SQL database was easy, since each record could have 1 state to multiple states, I just pulled all records and created one long string for them.

The end product looked like: NY, NC, SC, NJ, NY, OR, GA, OH, OH…

Now I wanted to separate all the data to a nice list and put it into an array like:

NC
SC
OH

To separate a string use the Split function:


Dim sep() As Char = ","
Dim sArrStates() As String
Dim sstates As String = ""
sArrStates = sstates.Split(sep)

The sep() line we are setting the character where we want to separate each word. Then with the split command we’re telling the program to split the sstates string at each “,” and put this list into the sArrStates Array.

Now to convert the state abbreviation to the state name. Using the StringDictionary function.


        Dim myCol As New StringDictionary()
        myCol.Add("AL", "AL-Alabama")
        myCol.Add("AK", "AK-Alaska")
        myCol.Add("AR", "AR-Arkansas")
        myCol.Add("AZ", "AZ-Arizona")
        .......

Before adding the state name lets put the states in alphabetical order.


Array.Sort(sArrStates99)

Now in one big swoop, Lets loop through the array, see if the state is listed in our StringDictionary, have another temp array to list the states into (this allows us to search the new array and if the current state hasn’t been added yet, add it to the new array and add it to the drop down list, if it is already listed in the new array, skip it)


'loop through the states array
For i = 0 To sArrStates99.Length - 1

            'check to see if abbrv. is in state list
            If myCol.ContainsKey(Trim(sArrStates99(i))) Then

                'copy the state name to a temp holding space
                TempState = myCol(Trim(sArrStates99(i)))

                'checks to see if the state is in the second array
                Dim WordToFind As String = Trim(sArrStates99(i))
                Dim WordIndex As Int16 = sDistinctStates.IndexOf(WordToFind)
                Dim j As Integer = 0

                'If state isn't in the second array, add it to the second array
                ' and add the state name and abbrv. to the dropdownlist
                If WordIndex < 0 Then
                    sDistinctStates.Insert(j, WordToFind)
                    DropDownList1.Items.Add(New ListItem(Trim(TempState), WordToFind))
                    j = j + 1

                End If


            End If

        Next
Nov
0

.Net Make CheckBox List act like RadioButtons

I had a site that I wanted to add a list of checkboxes but I wanted them to act like radiobuttons, which means I wanted the user to only be able to check one box and the others would clear out.

thanks to Mudassar Khan at aspsnippets.com he shows how this can be done with the .net checkboxlist and javascript.


<script type = "text/javascript">

    function MutExChkList(chk)

    {

        var chkList = chk.parentNode.parentNode.parentNode;

        var chks = chkList.getElementsByTagName("input");

        for(var i=0;i<chks.length;i++)

        {

            if(chks[i] != chk && chk.checked)

            {

                chks[i].checked=false;

            }

        }

    }

</script>

And then add the checkboxlist


<asp:CheckBoxList ID="CheckBoxList1" runat="server">

    <asp:ListItem Text = "1" Value = "1" onclick = "MutExChkList(this);">

    </asp:ListItem>

    <asp:ListItem Text = "2" Value = "2" onclick = "MutExChkList(this);">

    </asp:ListItem>

    <asp:ListItem Text = "3" Value = "3" onclick = "MutExChkList(this);">

    </asp:ListItem>

    <asp:ListItem Text = "4" Value = "4" onclick = "MutExChkList(this);">

    </asp:ListItem>

    <asp:ListItem Text = "5" Value = "5" onclick = "MutExChkList(this);">

    </asp:ListItem>

</asp:CheckBoxList>

The problem I ran into was I added a submit button to my site to email the response to myself, if a user chooses nothing you get an null error. I tried many different and usual ways to test for null or nothing but ended up going a little different.

I added one more line to the checkboxlist but made it equle none or nothing and made it not visible. This way when I get emailed it will show me none were choosen or you can go an extra step and code that if SelectedValue = “none” the user receives an error to chose one box.


<asp:ListItem Value="none" Selected="True" style="display:none" onclick = "MutExChkList(this);">None</asp:ListItem>

Aug
0

ASP.NET MultiLine TextBox, Wrap Doesn’t Work

So a short post on something I came across today at work. The title of this post is ASP.NET MultiLine TextBox, Wrap Doesn’t Work because that’s what I searched for and it took me forever to find the answer. Everyone wants to tell me to add the property of multiline, well I had that..

What was happening, I had a multiline textbox set up, but every time i’d type in the box it would just type on one line, I had set rows and columns correctly, but I had one thing incorrect, width and height.

I finally found the answer at aspalliance.com : (talking about row and columns)

Setting these properties does not limit the number of characters or rows the user can enter, only how many will display. Height and Width take precedence over Rows and Columns.

Yes, I had the textbox’s width and height set, I would think that once I chose to use multiline that MS would have stopped me from using those properties that can cause it to function incorrectly..  Oh well there;s your answer.. delete width and height

Aug
0

SweetCron and LifeStreaming

I’ve been playing around with SweetCron and LifeStreaming, trying to connect all my online activities together. SweetCron is a little tougher than wordpress since it’s still very much in beta and may things you have to edit config files yourself, but it’s starting to look good. When I’m finished, I’ll add a link here.

Jul
0

Old School ASP

Old School ASP

Taking a break from my .net. A company that we worked with decided to give up an old ASP site that we had been using on their domains, problem is that some of it wasn’t working correctly, so it was up to me to fix it. I’ve never messed with ASP before but it’s pretty straight forward and we didn’t want to spend alot of time on it and with it having about 50 pages we also didn’t want to rewrite it in .net, so fixing was the only option.

Getting IIS6.0 to run ASP pages

First problem was that our server was only serving asp.net pages so I needed to configure it to also server up ASP pages, luckly this is a quick fix..

To enable ASP pages

  1. In IIS Manager, expand the local computer, and then click Web Service Extensions.
  2. In the details pane, click Active Server Pages, and then click Allow.

Next problem.. The ASP site worked correctly on my localhost (XP) but once it was put onto the server, pages wouldn’t load and no error was shown, just an error 500 (HTTP 500 – Internal server error)

Showing ASP Errors on the Server

This was a bit more complicated, MS doesn’t want to show any ASP errors because this could help hackers debug and break into your server. But without the errors how are we as developers to fix what’s broken? (and don’t say a good coder doesn’t have errors lol). I finally found how to show ASP errors on a webserver or at least how to show HTTP 500 Errors for ASP:

To use the 500-100.asp file for error handling on the nondefault Web site, perform the following steps:

  1. Start the Internet Service Manager (ISM), which loads the Internet Information Services snap-in for the Microsoft Management Console (MMC).
  2. Right-click the appropriate Web site, click New, and then click Virtual Directory.
  3. In the Virtual Directory Creation Wizard, click Next. In the Alias text box, type IISHelp, and then click Next.
  4. When you are prompted for the path to the content directory, click Browse, select the WINNT\Help\IisHelp folder, and then click Next.
  5. On the Access Permissions page, accept all the defaults, click Next, and then click Finish.
  6. Right-click the Web site again, and then click Properties.
  7. On the Custom Errors tab, select the 500;100 error line, and then click Edit Properties.
  8. In the Message Type list box, select URL, and then type /iisHelp/common/500-100.asp in the URL text box.
  9. Click OK twice to return to the ISM.

This worked perfectly, I can now see my errors, quickly fix my errors and delete the above.

Feb
1

Why is Your Site Slow?

Why is Your Site Slow?
Image representing Firefox as depicted in Crun...
Image via CrunchBase

My wife and I have had a blog site for awhile but just recently we’ve started actually blogging on it. So quickly one night I added a new theme, updated the old version of wordpress that was on the site and added a few plugins for lightbox images and flickr images. Tested it, all was working so like the cobblers kids and their shoes, I would post sometimes but never gave the sites structure a second thought, till this week. I was showing a co-worker our site and realized it was taking awhile to load, it was my own site and I was ready to head to another site just to stop the loading.

It was time to figure out why my site was slow. There can be many reasons why the site is slow, a couple of the things to check are: Your Web Host, I’ve been with ours a long time and knew it wasn’t them. Routing over the Internet, this is usually when you notice your site is slow just one day, but usually is fast. By going to the run command in windows, typing in CMD and then in the command window type: tracert www.yourwebsite.com you will see the hops it takes to get to your site and the time it takes to get there. The lower the number the better, numbers above 100 maybe a problem. There isn’t anything you can do about this, but these problems are usually fixed in a day or two. This again was not my problem.

How to tell what is running slow on your site

To find out why my site was slow I needed a way to see each item loading on my site and the time it takes for them to load. The tool I chose was Firebug. Firebug is a plugin for Firefox (which you’d better be using by now!!) Download Firebug and install it into firefox, after restarting Firefox, you’ll see a small image of a roach in the bottom status bar of FF.

Using Firebug to test your site

Using Firefox, go to your website, once there, click the roach and go to the net tab. The net tab will have check boxes, check them and hit the enable button. your webpage will start to reload, as it’s loading you’ll see status bars showing how long it takes each item to load (see the header image). My problems were all  in red, not because they took so long to load but there were files missing, the slow site was caused by when the site would load, it couldn’t find important files for a couple of the plugins, so it would keep searching till it timed out. You may not have this problem, but you’ll be able to see if images are to large, javascripts are having problems or if you’re just loading to many objects.

Technorati Tags: , , , , , ,