Asp.Net: Wizard control highlight selected step

by Pieter Brinkman 26. March 2009 06:42

You can highlight the selected stap of the wizard control by editing the SideBarTemplate within the asp:Wizard control.

<SideBarTemplate>                        
    <asp:datalist runat="Server" id="SideBarList">
        <ItemTemplate>
          <asp:linkbutton runat="server" ID="SideBarButton"/>
       </ItemTemplate>
       <SelectedItemTemplate>
           <asp:LinkButton ID="SideBarButton" runat="server" CssClass="selected">LinkButton</asp:LinkButton>
       </SelectedItemTemplate>
   </asp:datalist>
</SideBarTemplate>


The ItemTemplate and the SelectedItemTemplate need to have a Button with ID SideBarButton.

 

Categories: ASP.Net | Controls

Asp.Net: Handle Usercontrol ClickEvent in Page

by Pieter Brinkman 24. March 2009 04:01

In this article we're going to create a usercontrol with a button. Place this usercontrol on a page and handle the clickEvent on that page.

Step 1, the UserControl

Create a usercontrol with a button called  'clickMeButton'.

In the codebehind of your UserControl define a delegate.

public delegate void ButtonClickedEventHandler(object sender, EventArgs e);


Then create a public EvenHandler.

public event ButtonClickedEventHandler ButtonClickedEvent;


Now add a click event to the button and on the click event fire tje ButtonClickedEvent.

protected void clickMeButton_Click(object sender, EventArgs e)
{
   ButtonClickedEvent(sender, e);
}

And the usercontrol is finished, now create a page to use the usercontrol.


Step 2, the Page

Create a new page. Add the usercontrol to the page, in the codebehind (Page_Load) attach your page to the ButtonClickedEvent.

UcWithClickEvent1.ButtonClickedEvent += new UcWithClickEvent.ButtonClickedEventHandler(UcWithClickEvent1_ButtonClickedEvent);


Press tab twice to generate the following Method.

void UcWithClickEvent1_ButtonClickedEvent(object sender, EventArgs e)
{
   throw new NotImplementedException();
}


Lets implement some basic logic to the event to test if the event is working

void UcWithClickEvent1_ButtonClickedEvent(object sender, EventArgs e)
{
   Response.Write("Button clicked");
}


Step3, the result

Here is the result after the user clicked the button within the usercontrol. As aspect-ed the Button Clicked text is shown.


You can download the example here (blogExamples.rar (17.87 kb))

Hope it helps!

Categories: ASP.Net | Controls

ADO.Net DataServices QueryString parameters

by Pieter Brinkman 18. March 2009 04:03

With ADO.Net Data Service you can add parameters in the Querystring. The following parameters are recognized:

  • expand 
  • orderby 
  • skip 
  • top 
  • filter


So if your request for all products was AdventureWorks.svc/Product you can add parameters like this AdventureWorks.svc/Product?$[paramatername]=expression

For the examples I use the Product table of the Adventureworks database.

Filter

Filter allows you to filter the selected result based on a expression. The expression has two types of operators: logical, and arithmetic.

The logical operators are:

  • eq  (==) 
  • ne  (!=)
  • gt  (<)
  • gteq  (<=)
  • lt  (>)
  • lteq  (>=)
  • and  (&&)
  • or  (||)
  • not  (!)

The arithmetic operators are:

  • add  (Addition)
  • sub  (Subtraction)
  • mul (Multiplication)
  • div  (Division)
  • mod  (Modulus)

Example
Let's say I want to have the product with the value 534 in the ProductId column.

[code:c#]
AdventureWorks.svc/Product?$filter=ProductID eq 534
[/code]

Result

[code:xml]
<entry>
    <id>http://localhost:55832/AdventureWorks.svc/Product(534)</id>
    <title type="text"></title>
    <updated>2009-03-11T08:22:23Z</updated>
    <author>
      <name />
    </author>
    <link rel="edit" title="Product" href="Product(534)" />
    <link rel="related/BillOfMaterials" title="BillOfMaterials" href="Product(534)/BillOfMaterials" />
    <link rel="related/BillOfMaterials1" title="BillOfMaterials1" href="Product(534)/BillOfMaterials1" />
    <link rel="related/ProductModel" title="ProductModel" href="Product(534)/ProductModel" />
    <link rel="related/ProductSubcategory" title="ProductSubcategory" href="Product(534)/ProductSubcategory" />
    <link rel="related/UnitMeasure" title="UnitMeasure" href="Product(534)/UnitMeasure" />
    <link rel="related/UnitMeasure1" title="UnitMeasure1" href="Product(534)/UnitMeasure1" />
    <link rel="related/ProductCostHistory" title="ProductCostHistory" href="Product(534)/ProductCostHistory" />
    <link rel="related/ProductDocument" title="ProductDocument" href="Product(534)/ProductDocument" />
    <link rel="related/ProductInventory" title="ProductInventory" href="Product(534)/ProductInventory" />
    <link rel="related/ProductListPriceHistory" title="ProductListPriceHistory" href="Product(534)/ProductListPriceHistory" />
    <link rel="related/ProductProductPhoto" title="ProductProductPhoto" href="Product(534)/ProductProductPhoto" />
    <link rel="related/ProductReview" title="ProductReview" href="Product(534)/ProductReview" />
    <link rel="related/ProductVendor" title="ProductVendor" href="Product(534)/ProductVendor" />
    <link rel="related/PurchaseOrderDetail" title="PurchaseOrderDetail" href="Product(534)/PurchaseOrderDetail" />
    <link rel="related/ShoppingCartItem" title="ShoppingCartItem" href="Product(534)/ShoppingCartItem" />
    <link rel="related/SpecialOfferProduct" title="SpecialOfferProduct" href="Product(534)/SpecialOfferProduct" />
    <link rel="related/TransactionHistory" title="TransactionHistory" href="Product(534)/TransactionHistory" />
    <link rel="related/WorkOrder" title="WorkOrder" href="Product(534)/WorkOrder" />
    <category term="AdventureWorksModel.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
      <m:properties>
        <d:ProductID m:type="Edm.Int32">534</d:ProductID>
        <d:Name>Top Tube</d:Name>
        <d:ProductNumber>TO-2301</d:ProductNumber>
        <d:MakeFlag m:type="Edm.Boolean">true</d:MakeFlag>
        <d:FinishedGoodsFlag m:type="Edm.Boolean">false</d:FinishedGoodsFlag>
        <d:Color m:null="true" />
        <d:SafetyStockLevel m:type="Edm.Int16">500</d:SafetyStockLevel>
        <d:ReorderPoint m:type="Edm.Int16">375</d:ReorderPoint>
        <d:StandardCost m:type="Edm.Decimal">0.0000</d:StandardCost>
        <d:ListPrice m:type="Edm.Decimal">0.0000</d:ListPrice>
        <d:Size m:null="true" />
        <d:Weight m:type="Edm.Decimal" m:null="true" />
        <d:DaysToManufacture m:type="Edm.Int32">1</d:DaysToManufacture>
        <d:ProductLine m:null="true" />
        <d:Class m:null="true" />
        <d:Style m:null="true" />
        <d:SellStartDate m:type="Edm.DateTime">1998-06-01T00:00:00</d:SellStartDate>
        <d:SellEndDate m:type="Edm.DateTime" m:null="true" />
        <d:DiscontinuedDate m:type="Edm.DateTime" m:null="true" />
        <d:rowguid m:type="Edm.Guid">4c0bad8e-066b-46b8-bfe9-da61539606e8</d:rowguid>
        <d:ModifiedDate m:type="Edm.DateTime">2004-03-11T10:01:36.827</d:ModifiedDate>
      </m:properties>
    </content>
  </entry>

[/code]

Expand

Example
Let's say we want to use the ProductReviews of the product in our application. To do this we need to load the ProductReviews values on request, we can achieve this with the expand paramater.

To get a clear view of what the expand parameter does I included the filter funtion on ProductId 534 so we can compare the results.

AdventureWorks.svc/Product?$expand=ProductReview&$filter=ProductID eq 534

Result

[code:xml]


<entry>
    <id>http://localhost:55832/AdventureWorks.svc/Product(534)</id>
    <title type="text"></title>
    <updated>2009-03-11T08:32:28Z</updated>
    <author>
      <name />
    </author>
    <link rel="edit" title="Product" href="Product(534)" />
    <link rel="related/BillOfMaterials" title="BillOfMaterials" href="Product(534)/BillOfMaterials" />
    <link rel="related/BillOfMaterials1" title="BillOfMaterials1" href="Product(534)/BillOfMaterials1" />
    <link rel="related/ProductModel" title="ProductModel" href="Product(534)/ProductModel" />
    <link rel="related/ProductSubcategory" title="ProductSubcategory" href="Product(534)/ProductSubcategory" />
    <link rel="related/UnitMeasure" title="UnitMeasure" href="Product(534)/UnitMeasure" />
    <link rel="related/UnitMeasure1" title="UnitMeasure1" href="Product(534)/UnitMeasure1" />
    <link rel="related/ProductCostHistory" title="ProductCostHistory" href="Product(534)/ProductCostHistory" />
    <link rel="related/ProductDocument" title="ProductDocument" href="Product(534)/ProductDocument" />
    <link rel="related/ProductInventory" title="ProductInventory" href="Product(534)/ProductInventory" />
    <link rel="related/ProductListPriceHistory" title="ProductListPriceHistory" href="Product(534)/ProductListPriceHistory" />
    <link rel="related/ProductProductPhoto" title="ProductProductPhoto" href="Product(534)/ProductProductPhoto" />
    <link rel="related/ProductReview" title="ProductReview" href="Product(534)/ProductReview">
      <m:inline>
        <feed>
          <title type="text">ProductReview</title>
          <id>http://localhost:55832/AdventureWorks.svc/Product(534)/ProductReview</id>
          <updated>2009-03-11T08:32:28Z</updated>
          <link rel="self" title="ProductReview" href="Product(534)/ProductReview" />
        </feed>
      </m:inline>
    </link>
    <link rel="related/ProductVendor" title="ProductVendor" href="Product(534)/ProductVendor" />
    <link rel="related/PurchaseOrderDetail" title="PurchaseOrderDetail" href="Product(534)/PurchaseOrderDetail" />
    <link rel="related/ShoppingCartItem" title="ShoppingCartItem" href="Product(534)/ShoppingCartItem" />
    <link rel="related/SpecialOfferProduct" title="SpecialOfferProduct" href="Product(534)/SpecialOfferProduct" />
    <link rel="related/TransactionHistory" title="TransactionHistory" href="Product(534)/TransactionHistory" />
    <link rel="related/WorkOrder" title="WorkOrder" href="Product(534)/WorkOrder" />
    <category term="AdventureWorksModel.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
      <m:properties>
        <d:ProductID m:type="Edm.Int32">534</d:ProductID>
        <d:Name>Top Tube</d:Name>
        <d:ProductNumber>TO-2301</d:ProductNumber>
        <d:MakeFlag m:type="Edm.Boolean">true</d:MakeFlag>
        <d:FinishedGoodsFlag m:type="Edm.Boolean">false</d:FinishedGoodsFlag>
        <d:Color m:null="true" />
        <d:SafetyStockLevel m:type="Edm.Int16">500</d:SafetyStockLevel>
        <d:ReorderPoint m:type="Edm.Int16">375</d:ReorderPoint>
        <d:StandardCost m:type="Edm.Decimal">0.0000</d:StandardCost>
        <d:ListPrice m:type="Edm.Decimal">0.0000</d:ListPrice>
        <d:Size m:null="true" />
        <d:Weight m:type="Edm.Decimal" m:null="true" />
        <d:DaysToManufacture m:type="Edm.Int32">1</d:DaysToManufacture>
        <d:ProductLine m:null="true" />
        <d:Class m:null="true" />
        <d:Style m:null="true" />
        <d:SellStartDate m:type="Edm.DateTime">1998-06-01T00:00:00</d:SellStartDate>
        <d:SellEndDate m:type="Edm.DateTime" m:null="true" />
        <d:DiscontinuedDate m:type="Edm.DateTime" m:null="true" />
        <d:rowguid m:type="Edm.Guid">4c0bad8e-066b-46b8-bfe9-da61539606e8</d:rowguid>
        <d:ModifiedDate m:type="Edm.DateTime">2004-03-11T10:01:36.827</d:ModifiedDate>
      </m:properties>
    </content>
  </entry>


Skip

Example all productreviews

AdventureWorks.svc/ProductReview


Result
 

Example skip productreviews

AdventureWorks.svc/ProductReview?$skip=2

Result
Only the last two ProductReview objects get returned.
 

Top

Example

[code:c#]

AdventureWorks.svc/ProductReview?$top=3

Result
This will return the first three product reviews.

Orderby

Example

[code:c#]

AdventureWorks.svc/Product?$orderby=Name

Result
This will sort the results by the column 'Name'.

You can also define build a more complex order clause by combining columns in a comma-delimited list, example:

[code:c#]

AdventureWorks.svc/Product?$orderby=Name desc,ModifyDate,ListPrice

Result
Only the product with ProductID values equeals 534 will be returned.

Combining attributes

You can combine the attributes. You can do this by creating a URL and seperating the attibutes with a '&', example;
AdventureWorks.svc/Product?$[paramatername]=expression&[paramatername]=expression

Example

[code:c#]

AdventureWorks.svc/Product?$expand=ProductReview&$filter=ProductID eq 534

 

Categories: ADO.Net

A new GoogleCSE platform

by Pieter Brinkman 4. March 2009 02:58

I finished building a Google CSE platform and deployed multiple .Net related searchenginges. 

 Let me know If you have good ideas or sites for the searchengines? 

More will follow.

 

 

Categories: Portfolio

Asp.Net: Caching Rss feeds

by Pieter Brinkman 3. March 2009 09:10

For dotNetSearch.net I needed to cache the RSS feed (on the right). I did this with the .Net Cache namespace.

if(Cache.Get(RssUrl) == null)
{
 RssDocument rssFeed = RssDocument.Load(new Uri(RssUrl));
 Cache.Insert(RssUrl, XDocument.Parse(rssFeed.ToXml(DocumentType.Rss)), null, DateTime.Now.AddMinutes(15), TimeSpan.Zero);
}

XDocument rssXml = (XDocument)Cache.Get(RssUrl);


In this examle I add the RSSFeed content as object in the cache and use the url of the RSS feed as Key. The Cache will expire (and cleared) after 15 minutes.

 

Categories: ASP.Net

SQLReporting service: Deployment

by Pieter Brinkman 3. March 2009 04:23

When deploying a project to a internal test server I got the following error:

The definition of the report 'Main Report' is invalid.
An unexpected error occurred in Report Processing.
Could not load file or assembly 'Microsoft.ReportViewer.ProcessingObjectModel, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
 

Fix this by adding a reference to ProcessingObjecdtModel.dll in you project. You can find the ProcessingObjecdtModel.dll in the GAC. The problem with the GAC is that you can't copy the .dll from the GAC using Windows Explorer. But you can copy the DLL with Command Prompt (cmd.exe).

To do this:

    1. Run -> cmd.exe
    2. cd C:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.ProcessingObjectModel\ 9.0.0.0__b03f5f7f11d50a3a
    3. copy Microsoft.ReportViewer.ProcessingObjectModel.dll c:\locationFolder\
  • This action will look like this:

    Copy the Microsoft.ReportViewer.ProcessingObjectModel.dll to your Bin folder or at a reference to the assembly.

    Hope it helps,

    Pieter

    Categories: ASP.Net

    Asp.Net: Charting Control (Error ChartImg.axd)

    by Pieter Brinkman 3. March 2009 02:49

    After installing and playing with the Asp.Net Charting control I decided to use it for a customer. When integrating the control to the project I got the following error

    "Error executing child request for ChartImg.axd"

    This error occurred because I did not update my web.config file. You have to add the following appSettingkey, httpHandler and handler.

    <appSettings>
        <add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFilesDit\;" />
    </appSettings>
    <httpHandlers>
        <add path="ChartImg.axd" verb="GET,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
    </httpHandlers>


    <handlers>
        <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </handlers>

    More info about the Charting control:
    http://weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt.aspx

    Enjoy charting,
    Pieter

    Categories: ASP.Net | Controls | Microsoft