Scott Hanselman posted a while back about a browsers definition problem with some ASP.NET sites that causes problems.  Microsoft has articles on this also.  Having just received my BUILD tablet that includes IE10, I tested the Silicon Valley Code Camp web site and discovered that when you login, then switch to another page, the login did not stick.  After uploading the two files Scott mentions (firefox.browser and ie.browser), the problem goes away.

Thanks Scott for the heads up.

 

image

The What and Where

Something that may not be obvious is if are creating an asp.net WebForms project and you put a datasource such as SqlDataSource or ObjectDataSource for example on the page, how can you prevent the SqlSelect associated with that datasource from being triggered.

The answer is to set the control’s visible property to false.  That’s it!

(more…)

There are 10,000 ways to do this.  Back way back when (ASP.NET 1.1) days, we would have created either a custom control to do this, then added a Repeater control on the page to display it.  Well, the Silicon Valley Code Camp Website was started back in those days and since what I want is so simple, I decided to do just that (minus the custom control).  I really only wanted to spend about 10 minutes doing this, and as it turned out, it took about 30.  Oh well, 3x plan verses execution.  Could do better next time.

So, here is basically what I want on the left side bar of the home page of Silicon Valley Code Camp:

(more…)

In this post, I’ll show a simple example of how when you add a parameter to C# method, ReSharper gives you a simple prompting to ask if you want to add a parameter to your method, or create an overloaded method that gives you the flexibility to maintain the old method signature and have the new method.

(more…)

I’ve recently started using Microsoft’s WCF Data Services which supports OData Services.  What this means is that we can access resources by simply specifying a URI.  This concept greatly simplified building an ORM layer on a web site, as well as creating the linkage between the server side data and the client side application, which in my case is usually a browser.

So, the issue this blog addresses is that if you form a URI with the parameter $top={anything}, your data will automatically be sorted.  The documentation for OData on top basically says that, but it could be clearer.  It says the following:

“If the data service URI contains a $top query option, but does not contain a $orderby option, then the Entries in the set needs to first be fully ordered by the data service.”

What actually happens is when you use the orderby clause, the data will be sorted 100% of the time for you, whether you do it or not.

(more…)

At tonight’s meet up, we will be having several short presentations on the new features in ExtJS version 3.0.  For my short presentation, I will be showing how to build a simple asp.net application that lets you Create, Update, Delete and Edit Membership data using the ASP.NET built in membership providers.  I will be leverage code from an MSDN article I wrote a while back here along with the URL to the meetup location.

http://www.meetup.com/The-San-Francisco-ExtJS-Meetup-Group/calendar/10302891/

http://msdn.microsoft.com/en-us/library/aa478947.aspx

My plan is to do a progression where I start with a trivial GridPanel, then work myself in 5 steps to a full working membership editor that looks like this:

(more…)

So, the problem is you have a list that you want to retrieve from that contains multiple values.  Say for example, you have a list of 5 cities and you want to retrieve a list of people in some combination of those cities.  If you use the class SelectValue method with GridView you run out of steam because it’s only one value.  What you’d really like to do is pass the CheckBoxList into the GridView as a selection parameter, but unfortunately, when you do that, you just get the one selected value from the CheckBoxList, not all the values.

I’m sure you can make a custom ControlParameter in ObjectDataSource to solve this, but I really don’t have time for that.  I just wanted something quick (which I now have and thought I’d share).

(more…)

In my previous post, Assigning a DropDownList Value in a ASP.NET GridView Using ObjectDataSource, I discussed how to put a DropDownList value in a GridView.  As I explained, my motivation was to answer a common question that appears on often on the forums.  If you are wondering what my process is for deciding what to answer, there really is no process besides I see yet another question on the forum about this, and rather than answer it again, I write a post explaining it, then point my answer to the question at the post.  This is what I did yesterday and below is the response to this forum post.

x

(more…)

As a moderator in the asp.net forums, I often see the same or similar questions.  The answer to this question is pretty straight forward but not 100% obvious so I thought I’d do a post about in the hopes that with a couple key words, people will find the answer.  The title basically says it all.  We have a GridView that has a data column of type bool.  We want to display in the GridView Yes or No depending on whether the data value is true or false.  The example I’m showing does not help with making this an editable field (maybe a theme for another post if this one is popular) but simply shows yes or no.

The solution involves first dropping a GridView and ObjectDataSource onto your design surface in Visual Studio.  Then, using the little chevron on the GridView, choose edit columns and convert the column you are interested in making a DropDownList into a template.  From there replace the ItemTemplate with the DropDownList code below.  You get the code below.

 

<%@ Page Language="C#" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<script runat="server">
 
</script>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>ODS DDL Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetMembers"
            TypeName="BusinessObject"></asp:ObjectDataSource>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id"
            DataSourceID="ObjectDataSource1">
            <Columns>
                <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
                <asp:TemplateField HeaderText="Approved" SortExpression="Approved">
                    <ItemTemplate>
                        <asp:DropDownList ID="DropDownListUser" runat="server" AutoPostBack="False" 
                            SelectedValue='<%# Bind("Approved") %>'>
                            <asp:ListItem Text="Yes" Value="True"></asp:ListItem>
                            <asp:ListItem Text="No" Value="False"></asp:ListItem>
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>

 

And, when you run this code (assuming you have a simple business object that returns some data), you get this:

 

x

Hope this helps!

Windows Powershell is something I’ve been meaning to learn for quite some time.  It started out as the Monad Project at Microsoft and I remember seeing it discussed at Code Camps but never spending the time to go.  I thought it was just another command.com with special commands.

Turns out, I was very wrong.  As far as I’m concerned, it’s strength is that you can reference .net assemblies directly.  That means, you can access everything in .Net just like a first class language.  Be that C# or VB, you can get to all of it.  You can write your own assemblies and reference them as well!  It of course if fully object oriented, very rich, and full error handling.  Very cool

(more…)

So, technically, String and string mean exactly the same thing in C#.  string, is an alias for String (aka a shorthand) for System.String.  So, when should use which?  It seems that the convention is to use string when you are referring to an object and String when you are referring specifically to the string class.

This is basically what is said at this URL:  http://en.csharp-online.net/CSharp_String_Theory%E2%80%94string_versus_String

Juval Lowy has some coding standards at http://www.idesign.net that says basically the same thing.  From the document on IDesign’s web site the following examples show what is best practices (which I completely agree with).

idesign1                            idesign2

That’s it for now. 

So, I’ve been preaching for a long time that it’s best to use the Using pattern when working with anything that implements IDisposable.  That way, you don’t have to worry about calling Dispose, or calling Close.  The framework will just do it for you.  I’ve answered this question on the forums several times so I thought I’d past some code I’m doing right now for simple ado.net stuff.  It’s actually code that is inside a business object that I hook up to an ObjectDataSource in asp.net 2.0.

The code is posted below.  I think you’ll get the idea.

(more…)

(Using Membership ObjectDataSource From MSDN Article)

I’m doing a project where I have lots of DropDownList’s on a page and want a simple way to set the initial values based on some known value.  The DropDownLists are retrieved using ObjectDataSource but I don’t want the first value displayed.  I wrestled some with how to do this using page_load or page_prerender but didn’t come up with good solutions.  I did finally
decide that programming the databound event of the dropdownlist was probably the best way to go.

The solution is pasted below.  The MembershipUtilities.MembershipODS c# code can be downloaded from MSDN or on my web site at the following location. 

(more…)

Recently, is seems that many web sites and blogs are starting to use a navigation technique where you have multiple hyperlinks grouped in a box, with size, color, or brightness giving some meaning.  I like this very much and have been on the lookout for a while for a control to do this in ASP.NET.  Turns out, DevExpress has one!  It’s called the CloudControl and you can read more about it at the following URL.

(more…)

(User MapPath and FileStream Together)

A very common scenario we often run into is we need to log some information to a local text file on the web server.  We know we can use all the health monitoring capabilities built in to asp.net for reasons like performance,
standards, best practices, etc., but sometimes, you just want to log something right now and you don’t want to spend a lot of time.

(more…)

One of the tricks I’ve learned over time is to always set visual studio to stop on a thrown exception.  Normally, during running of a .net application, unhandled exceptions are simply processed and absorbed quietly.  For the most part, this is good because you do not want your users to see error messages all the time, and likely what is being thrown is not interesting anyhow.  It is however bad because throwing exceptions is very time consuming for the application as well as it may actually be something important.

To keep this from happening, my "best practice" is to go into the menu choice Debug/Exceptions as follows:

Debug Excetpion Menu Choice

(more…)

TechEd 2007, Orlando

Visual Studio Debug/Trace Tricks From the Learning Center With Steve Carol

I love these meetings!  I have to admit that I come not for the sessions, but for the learning center.  At the moment I’m working on a .net Silverlight application and I’ve got lots of problems.  What I do is put the mark $$$ in my code in all the places where I’m having problems.  I trek over to the learning center area and sit down with a Microsoft engineer who is willing to tolerate me.  Today, the guy was Steve Carroll who I believe is a manager on the visual studio performance team.  Score!  Big time help, and some bonuses also.  Steve didn’t really know anything about WPF
or Silverlight but knows c# very very well.  I asked him if he was a c# wizard at the start and he said no.  He was very wrong about that.

(more…)

The Visual Basic Version of the Objects!

Back in January of 2006, I published on MSDN an article and source code for managing ASP.NET 2.0 Membership users with an ObjectDataSource.  Since I’m not much of a VB person, I only published them in c#.  since then, I’ve had hundreds of requests for this code in VB.  Until now, I’ve had to send an excuse for not having it. Now, thanks to Dave at  Tangible Solutions Software, we now have a VB version.  Dave converted it with there conversion software called Instant VB.

The following zip file includes these VB objects along with a very simple aspx page in VB.  It does not include any more complete examples of using the objects because the code associated with the aspx pages I wrote is all in c#.  If anyone wants to convert the other pages, I’d be happy to post those also.

Thanks Dave and Thanks Tangible Solutions!

http://peterkellner.net/DownLoads/MembershipEditorVB.zip

Rock And Roll Code Camp in Los Angeles Presentation

This is the first time I’ve presented this material. I’ve presented on several previous occassions the basic
material on how to build an ObjectDataSource class from scratch but this time was different. Inspired by people
often asking me "what good is the ObjectDataSource", I decided to create a useful example. Since the ObjectDataSource is inherently a complex abstraction, creating a real life demo that can be presented in a short amount of time is a challenge. In this presntation, I hopefully rose to the challenge. Below is the abstract along with the URL to the actual codecamp. Below that is a link to the project that was created at class for
anyone interested in seeing the material.

(more…)

Introduction

A question that frequently comes up in the asp.net forums is how to have a gridview show the the last record added highlighted. This articles gives a technique for doing this. It only works with SqlServer but could could be modified for other databases.

What It Looks Like Running

After pressing the insert button on the screen shot below, the bottom line was actually added and it is automatically highlighted. This is in a nutshell, what the code listed below and this article discusses.

(more…)

© 2012 PeterKellner.net. All Rights Reserved