Pages

Thursday, August 30, 2007

ASP.NET 2008 Beta: '"SqlDataSource1";' could not be found.

When you get this error in Visual Web Developer 2008 Beta:

The DataSourceID of 'GridView1' must be the ID of a control of type IDataSource. A control with ID '"SqlDataSource1";' could not be found.

do this:

Find the Code that looks like this:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSource1"; EmptyDataText="There are no data records to display." GridLines="Vertical"

...and remove the semicolon (;).

Thursday, August 16, 2007

Irrelevant Crap!

Thank you for participating in our beta test. Please tell us how we can improve Visual Studio for you

STOP INCLUDING IRRELEVANT CRAP IN THE HELP SEARCH RESULTS

Update!

Let's add THIS to the list of irritations while we're here!

Config Files: a primer

to use a config file in your project, first right-click the project name and Add a New Item:

pick Application Configuration File and give it a name:

Wednesday, August 15, 2007

Adding a printer

How to programmatically add a printer.

This will show how to add a printer to the current Windows workstation's Printers and faxes page. This will effectively render the printer usable by the workstation.

Here's the code example.

...
using System.Runtime.InteropServices;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        [DllImport("winspool.drv", SetLastError=true)]
        public static extern bool AddPrinterConnection(string pName);

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (AddPrinterConnection("\\\\PrintServer\\PrinterName"))
            { MessageBox.Show("ok"); }
            else
            {
                throw new Win32Exception();
            }
        }
    }
}

Splitting Strings without Regex

I have this string that I want to parse the server name out of. It looks like \\server-name\printer-name\. This turns out to be a piece of cake in C#, even without Regular Expressions. Here's the code.

 private void button1_Click(object sender, EventArgs e)
  {
      string[] parsed;
      parsed = textBox1.Text.Split(textBox2.Text[0]);
      listBox1.Items.Clear();
      if (parsed.Length == 4)
      {
          listBox1.Items.AddRange(parsed);
      }
      else
      { listBox1.Items.Add(parsed.Length.ToString() + " items found"); }      
  }
What happens here is that if the string conforms to the pattern \\server\printer, then it parses into the string array parsed. Here are some examples of how it works:

Easy, huh!

Sunday, August 12, 2007

Creating and Using Arrays in C#

Most of my history is with Borland/Inprise/Borland/CodeGear Delphi, so what I am trying to demonstrate is how to take a construct like these:

var
  States: array[0..49] of String[2];
  Counties: StringList;
begin
  Counties:=TStringlist.Create;

In this demo, States is an array of 50 string[2] variables indexed from 0. Counties is a re-sizable list of strings. A fixed array is a data type, while a TStringList is a class object. How do we do arrays in C#?

Here is an example of the declaration (and optional initialization) of a fixed array...

        public string[] States = new string[50] 
        {
            "AL","AK","AZ","AR",
            "CA","CO","CT",
            "DE",
            "FL",
            "GA",
            "HI",
            "ID","IL","IN","IA",
            "KS","KY",
            "LA",
            "ME","MD","MA","MI","MN","MS","MO","MT",
            "NE","NV","NH","NJ","NM","NY","NC","ND",
            "OH","OK","OR",
            "PA",
            "RI",
            "SC","SD",
            "TN","TX",
            "UT",
            "VT","VA",
            "WA","WV","WI","WY"
        };

Here is a collection, the equivalent of a Stringlist or TList.

        public ArrayList Counties = new ArrayList();

Now I'll pop some dialog messages to show we know what's in the array and in the collection... of course we have to first load something into the collection, so I created a button and wrote this code...

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("State 23 is " + States[23]);
            Counties.Add("Maricopa");
            Counties.Add("Sacramento");
            Counties.Add("Los Angeles");
            Counties.Sort();
            string temp = "";
            foreach (string S in Counties)
            {
                temp += S + "\n";
            }
            MessageBox.Show(temp);
        }

This code when compiled (after you resolve the missing using clause) gives this result...

Monday, August 6, 2007

Embedding CSharp output into a web page.

Ok, so I wanted to make a gallery page that reads every JPG in my /gallery path, and presents them in a page. So I tried to put a "placeholder" object, and fill it with stuff on C# code on Page_Load.

No Dice.

I tried a bunch of other things, but the only thing that worked was to use a Label component, and in the C#, set Label1.text to include all the HTML I wanted to embed in the page. The Label component seems to me to be an odd control to use for this. Is there a better way, or is this what labels are made for?

Here is the page.

Another First (or last) from Microsoft!

Apparently Internet Explorer is the only browser in existence that still does not support transparent png graphics! Check this out from my test website over the weekend!

According to the wikipedia, I can solve this by reducing the png from 24 bit to indexed, effectively using it just like a gif.

Saturday, August 4, 2007

Error: Unrecognized attribute 'xmlns'. Note that attribute names are case sensitive

Visual Web Developer 2008 After publishing a newly created website to an existing server (after updating the .NET framework). I browse to the website from my workstation and get:

Error: Unrecognized attribute 'xmlns'. Note that attribute names are case sensitive

...in this file:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config

Here is what to do.

  1. Edit the web.config file (get the filename from the bottom of the error message) . Make sure you're opening the version on the SERVER, not your local workstation.
  2. find every occurrence of the text xmlns="", and DELETE it. Do NOT delete the line that has a long filename in the "" marks.
  3. Save.
  4. Go back to your workstation and refresh the browser.
After a long time, it refreshed for me. It was like the webserver had to re-initialize first. Then it started acting normally.

Friday, August 3, 2007

Ok, What am I doing wrong here...

My web page looks like this in my local machine:

So I "publish" it. to the webserver, which is 4 feet to the right.

Ok, let's go to the live website and compare to the test website...

Ok, Parser Error Message: Child nodes not allowed. What does that mean? Apparently there is an error in my web.config file, which I never touched... It was generated automatically from Visual Web Developer. From my decades of programming experience, I am estimating that it's because I need to add the beta version of the .NET library to my server. But why cant the error just say You have to upgrade to the latest version of the .NET Framework to view this page?

I am upgrading the server now (should take an hour). I will bet you that it requires a reboot and that there is still an error after the upgrade is complete.

Meanwhile, let's look for this error in the help system. Searching for <providerOption name="CompilerVersion" value="v3.5"/> Let's search the Help!

Nothing. Lets check the questions site... Oh this is nice: from this page:

That's why it's called a BETA there champ...It has bugs.

Real helpful there... Ok lets run this error by Google.

Ok, turning to Google.

There is a really good post here - it's a lot of reading but it seems like they have a handle on the problem. Why is there nothing about this on the Microsoft site? I can't believe they have never heard of this problem!

Visual Web Developer 2008: First Look

Last night after hours of downloading, I got the VWD 2008 beta! Cool. It is a little easier to use than 2005 and they have kept the ability to design great websites that will not deploy to your webserver. I would show you a screen snap of the beautiful site I designed, but this is what I got when I tried to load my project this morning.

--------------------------- Microsoft Visual C# 2008 Express Edition --------------------------- 'C:\Documents and Settings\Some_Yahoo\My Documents\Visual Studio 2008\WebSites\AFI2\' cannot be opened because its project type () is not supported by this version of Visual Studio. To open it, please use a version that supports this type of project.


I figured it out: I was trying to open the Visual Web Developer Solution file in Visual C# Express. Bonehead move!

Wednesday, August 1, 2007

Downloading VS 2008

I downloaded VS 2008 today. It took about 3 minutes to download, then then just sat there for about 25 minutes installing. How could it take that much time, now that it was all on the local disk drive? Weird.

Furthering the weirdness, I am trying to remotely install the same thing on my dev machine from work, and every 10 seconds Norton pops up asking if the install can access the internet. So I can't set it running and forget about it, I have to sit here and monitor it.

Share This!

Contact Us

Name

Email *

Message *