Some tips for the Asp.net dropdown control

by Pieter Brinkman 30. December 2008 04:41

I always have problems implementing the Asp.Net dropdown control. Here are some simple tips to make your life (with dropdown controls) easier.

Adding an default item with data binded dropdown

To add an default listItem to your data binded dropdown list you just have to add a ListItem on the first place (0) of your control

[code:c#]

CountryDropdown.DataSource = countryList;
CountryDropdown.DataValueField = "CountryId";
CountryDropdown.DataTextField = "CountryName";
CountryDropdown.DataBind();

//Add the item
CountryDropdown.Items.Inser(0, new ListItem("-- Choose a Country --"));

[/code]


Getting the selected value

[code:c#]

CountryDropdown.Items[CountryDropdown.SelectedIndex].Text;

[/code]


Setting dropdown listitem by value

[code:c#]

dropDownList.SelectedIndex = dropDownList.Items.IndexOf(dropDownList.Items.FindByValue(option.OptionValue));

[/code]

 

Validation on a dropdownlist

[code:c#]

<asp:RequiredFieldValidator id="reqGroupDDL"
        Text="Choose group"
        InitialValue="selectGroup"
        ControlToValidate="GroupDDL"
        Runat="server" />

[/code]


Hope it helps.

Categories: ASP.Net | Controls

HTTP Error 404.17 with IIS7 (Vista)

by Pieter Brinkman 22. December 2008 09:51

While playing with IIS 7 I accidental destroyed my IIS (XML) settings file. To fix this problem I copied the .XML from a colleague PC to mine. After this my IIS started giving a strange error:

HTTP Error 404.17 - Not Found - The requested content appears to be script and will not be served by the static file handler.

After a quick search I found out that I copied the .XML from a 32 bit PC to my 64 bit Vista and that all my Application Pools where now running on 64-bit. So my application stopped working because it's 32 bit.

To fix this problem go to IIS, right click your Application Pool and set the Enable 32-bit Applications to true.

 

Categories: iis

MSSQL: Database diagram support objects cannot be installed because this database does not gave a valid owner.

by Pieter Brinkman 13. December 2008 05:35

For a customer I needed to do a review there database (MSSQL 2000 database). For this I wanted to create some database diagrams. When I tried to create a diagram with Sql Sever Management Studio I got the following message:

"Database diagram support objects cannot be installed because this database does not gave a valid owner."

To fix this problem you need to set the owner and change the Compatibility Level of the database. You can do this with the following steps within Sql Sever Management Studio:

1. Right Click on your database, choose properties
2. Goto the Options Page
3. In the Dropdown at right labeled "Compatibility Level" choose "SQL Server 2005(90)"
4. Goto the Files Page
5. Enter "sa" in the owner textbox, or any other user you want to be the owner.
6. Click the OK button

Categories: MSSQL

Convert XmlElement to XElement (Extension Method)

by Pieter Brinkman 8. December 2008 05:31

I was using some web-services that returned there values in an XmlElement. I needed to convert this XmlElement to something that I can use with LINQ. I didn't find good solutions on the internet. So I started building my own convert logic. After all kinds of solutions I ended up with creating an new XmlDocument, adding the XmlElement to the XmlDocument and then convert the innerXml of the XmlDocument to an XElement. Not really nice but it does the trick.

I've rewritten the code into a Extension Method for the XmlElement.

public static XElement ToXElement(this XmlElement xml)
{
   XmlDocument doc = new XmlDocument();

   doc.AppendChild(doc.ImportNode(xml, true));

   return XElement.Parse(doc.InnerXml);

}


You use the Extension Method like this:

XmlElement xmlElement = wsClient.DoWebServiceRequest();
XElement xml = xmlElement.ToXElement();


Please tell me if you have a better way of doing this!

Cheers,
Pieter

Categories: Linq | XML

Asp.Net Membership: Set url to the login page

by Pieter Brinkman 4. December 2008 08:46

The loginstatus control doesn't have a property to set the url of the login page. You need to set this URL in the web.config of your application.

Insert the login URL between the authentication node of the web.config. So it looks like this

<authentication mode="Forms">
 <forms loginUrl="~/pages/login.aspx" />
</authentication>

Change the value of the loginUrl to your login page.

Categories: ASP.Net

Silverlight Crossdomain file

by Pieter Brinkman 4. December 2008 05:26

An example of a clientaccesspolicy.xml

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="*">
        <domain uri="*"/>
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

An example of a crossdomain.xml

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
  <allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>


For more info you can read this weblog post.

Categories:

Run website on IIS7 (Vista) in classic mode

by Pieter Brinkman 3. December 2008 06:07

If you run your website on IIS7 you can run into the following HTTP errors: 500.22, 500.23

An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.


If you don't want to change your web.config and still want to run the website on IIS7 you have to change the Application Pool of your Website.

Open IIS, go to your Application Pools, find your Application Pool and double click the Managed PipeLine Mode.

 

Set the Manage Pipeline mode from Integrated to Classic.


Set IIS7 Application Pool Defaults
You can also set the Manage pipeline mode in the Application Pool Defaults. You can do this in IIS7 by clicking on Set Application Pool Defaults.

 

And then change the Managed Pipline Mode to Classic.

 


The other way is changing your web.config to work with IIS7. You can get more information about this by reading this post.

 

Categories: ASP.Net

Silverlight: Add .xap as MIME Type to IIS

by Pieter Brinkman 2. December 2008 09:01

When I tried to run a my Silverlight App on IIS7 I got the following error:

Microsoft JScript runtime error: Sys.InvalidOperationException: InitializeError error #2104 in control 'Xaml1': Could not download the Silverlight application. Check web server settings


The solution for this problem is adding .XAP file extension to your IIS MIME Types. The MIME type is application/x-silverlight-app.

If you don't know what a MIME Type is read this post.

Categories: Silverlight

CSS: Place vertical text

by Pieter Brinkman 1. December 2008 05:16
For a html report I needed the Excel functionality to put text vertical. I didn't know that this was possible but it is.
Put the following code in your page (style in the style section of the head or style sheet of course).
.verticalTextBottomTop {
writing-mode: tb-rl;
filter: flipv fliph;
}
 
.verticalTextTopBottom {
writing-mode: tb-rl;
filter: fliph fliph;
}


<div class="verticalTextBottomTop" style="height: 200px;">Text verticalTextBottomTop</div>
<div class="verticalTextTopBottom" style="height: 200px;">Text verticalTextBottomTop</div>


[/code]
 

To prevent word wrap you need to set the height property of the container.

And you get the following output.

IE7

FireFox

 

So as you can see It doesn't work for firefox. I can use it because my project is running under a controlled environment, where all users can only use IE.

Tags: , , ,
Categories: CSS