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…)

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!

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…)

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…)

The article below has a minor improvement to the previous article listed on this web site. Specifically, the previous article used the DropDownList as a mechanism to actually retrieve the data for the purposes of storing it in a local Dictionary. This article simply calls the ObjectDataSource directly to retrieve an IEnumerable type and iterates over that. Below is article with the updates. (Original Article is: http://peterkellner.net/2006/08/30/smalllistaccess/)

Most data driven web sites have to manage lots of small lists. Examples include things like states, countries, levels, and even things like sex where you may only have two choices. (especially if you have internationalization issues). The simplest way to store this information is in static lists simply defined programatically. Below is an example of this.

(more…)

Abstract

This article shows how to use Expression Builders in ASP.NET 2.0 to retrieve the current logged in user. DataBinding will not work so Expression Builders is the ticket. A small source file is created, the references to web.config are shown and a simple example is built.

The Problem

I recently was looking at unanswered posts in the asp.net forum, specifically this one: http://forums.asp.net/thread/1402259.aspx. I thought I
understood how databinding and expressions worked, but just wanted to check myself. So, I made a simple example
web page just like the post shows. (see below)

(more…)

Performance Comparison

Recently, I’ve been wondering what the difference is between rendering an image using IIS’s built in file handling capabilities, or using the asp.net with a custom handler. I decided to do a little test program to simply see the difference in clock time for processing such requests. The results of this test clearly show that IIS is faster. Sometimes a little, and sometimes a lot. I decided to test three size images, and run them each 10 times. Often, there is a start up lag time so the iterations should wash that out.

The table below basically sums up the results pretty well. The resolution of my timer is not great so for small images (35KB), both IIS and the handler processed the image in under 15 milliseconds. There may be a difference but in
my case, it was probably not measurable because of all the other time involved in the request. For Medium size images (550KB), difference is more consistent. Again, it’s a timer resolution problem that makes 15 milliseconds probably something related to a CPU click of sorts. For large images (5.6MB) you can clearly see a difference. The time it takes for the handler to process the image is almost double that of IIS.

(more…)

Microsoft just published my fourth article. This one is titled: "Microsoft ASP.NET 2.0 Member/Role Management with IIS, Part 4: Adding Personalization with Profiles to the ObjectDataSource".

You can find it on MSDN here, or on my blog here.

Here is the introduction.

(more…)

Microsoft just published my third article. This one is titled: "Member/Role Management with IIS, Part 3: AJAX Enhancements with Microsoft’s Atlas".

You can find it on MSDN here, or on my blog here.

Here is the introduction.

Introduction

This article extends one of the web pages developed in Part II of this series using Microsoft’s implementation of AJAX called Atlas. It utilized two techniques for reducing web server traffic to the browser to enhance the users web experience. The first technique uses the UpdatePanel tags to limit the refreshed area of the web page to limited areas and the second has to do with implementing some javascript using Atlas techniques so that the web page is updated on every key stroke in a textbox. A user list is displayed based on what is actively typed into this textbox. After reading this article the developer will be able to implement AJAX (Microsoft’s implementation Atlas) in their own application.

( ObjectDataSource1.Insert(); )

ObjectDataSource’s are great for building your own middle tier between your aspx web page and your database (or any other datastore for that matter). By binding the datasource to a databound server control like detailsview, you auto-magically get the insert behavior you are looking for. If however, you just just want to insert to the ObjectDataSource you have included on your aspx page without using a databound control, you don’t have a lot of fancy footwork to do. All you have to do is reference the insert parameter by name (or index offset) and assign it directly.

(more…)

Also published on Microsoft’s MSDN Network at Microsoft ASP.NET 2.0 Member/Role Management with IIS, Part 4: Adding Personalization with Profiles to the ObjectDataSource

Applies to:

  • Microsoft ASP.NET 2.0
  • Microsoft Visual Studio 2005
  • Microsoft Internet Information Services

(more…)

Mikhail Lukyanau has been kind enough to provide a redesigned version of the membership.aspx page. The source file for this can be downloaded at (Download New File). Below is a screen shot of this new look.

Figure 1 – Updated Design for Membership.aspx By Mikhail Lukyanau

 

I was recently asked how to use the Membership Data Object to return the unique ProviderKey generated by the Membership object. This may be necessary if want to associate the membership data with an existing table. That is, add a foreign key "ProviderUserKey" to another table so you can track an existing user to your current database without getting involved in extending the base provider. You can of course extend the existing provider to include other fields, but in general, you probably are better off maintaining your own tables rather than extending the provider model. Peter Dawson does an excellent job of explaining and showing how to extend the Membership Provider in his article Creating a Custom ASP.NET Provider. (published on theserverside.net)

(more…)

© 2012 PeterKellner.net. All Rights Reserved