Showing posts with label ASP.NET. Show all posts
Showing posts with label ASP.NET. Show all posts

Tuesday, August 26, 2008

Textbox submit NOW!

So, http://aspnet.4guysfromrolla.com/articles/060805-1.aspx.

Good ol' Internet Explorer won't handle a button click event with a page postback form an enter key with only 1 textbox.

Solution:
1. Add an invisible textbox (as the solution from above article)
2. Put in a panel and set DefaultButton

Thursday, August 14, 2008

Row Numbering

I came across a precarious situation today at work. I needed to write a paging stored procedure for use with a DetailsView. The situation and solution for start to finish is described at http://microsoft.apress.com/index.php?id=51. Unfortunately the sql database was currently running on an instance of sql 2000. Row_Number() is a specific function avaliable with sql 2005, not sql 2000.

The sql query I developed seems to work for an equivalent to Row_Number(). My case only had one sorting method, and I know that my column that is being sorted is unique. thus simplifying some matters.

Let's presume we have a Table1 with columns ID as an int, Code as a varchar, and Name. Table1 should be sorted by the column Code.


SELECT ID, Code, Name
(SELECT COUNT(ID) AS Expr1
FROM Table1
WHERE (Code < (SELECT Code FROM Table1 WHERE (ID = t.ID)))
) AS RowNum FROM Table1 AS t ORDER BY Code


Whilst this may not be very efficient or pretty, it gets the job done. Basically this query has a sub query to count the number of rows that are less than the current Code (which is selected by a further sub query).

Unorthodox probably, as bad as a GOTO statement maybe, works under the right circumstances.

Wednesday, August 13, 2008

Viewing the details

Frustrations I came about using DetailsView for asp.net that are obvious but can be overlooked.

For custom Next/Previous/First/Last buttons:
CommandName="Page" CommandArgument="..."
[Command arguments paramters]
Yes the buttons need to be in a template of the DetailsView control, they cannot be outside. Make sure they aren't outside if they aren't working....grrrr.


To access an item in the Pager template:
DetailsView1.BottomPagerRow.FindControl("...")

In the aspx page, set the DataKeyNames to allow SQL Statements to be updated/deleted.



Cheers,

Friday, August 01, 2008

Reporting Work

At work I've been assigned to upgrading reports that are in Access and Crystal Reports into SQL Server Reports. The project website is being developed in Visual Studio 2008 with the 3.5 framework. Naturally we wanted to develop the reports and have them contained in the 2008 project. Visual Studio 2008 supports reports but does not support a Report Server Project. My frustrations and solution to reports in VS 2008 is found below, however, we decided to stick with developing the reports in VS 2005 (BIDS).



Here is the best solution I was able to come up for building reports in Visual Studio 2008.


1. Create a new web application project (or open the your current project).

2. Add New Item to your project. Select a Report and give it a name. Note that these reports are rdlc not rdl. ( http://msdn.microsoft.com/en-us/library/ms252109(VS.80).aspx for information on rdlc versus rdl)

3. Now to add the dataset for the report data. Add New Item again, this time add a DataSet. This should walk you through a wizard for adding a new DataSet. Note that if you have a connection string in your web.config file to point to a database, you WILL still NEED to add a NEW connection string. It will give you servers to choose from that currently exist in the Server Explorer. Once you add a new connection string through this dataset wizard it will be avaliable for the next TableAdapter that you add. Grrrr... I'm going to stop here because I have many gripes...



4. A tableadapter for a dataset that you want for a report should now exist. Go back to the Report rdlc file (you may have to click around on the design area to get all the menu items to show up) and select Report, Data Sources..., find the DataSet that you just created and Add to Report

5. Build the report now that you have the dataset information.


Now let's say you have built many reports and want to use 1 report viewer to dynamically display the reports in a report viewer. Add a new page or open an existing aspx page. Add a Report Viewer to the page. (This is were I think things get ugly, and there may be a better solution, feel free to post a comment if there is a better solution)

Report View definition on aspx page:




The code behind to have the report viewer set the report:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Report is going to run local on the website
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local
ReportViewer1.LocalReport.DataSources.Clear()
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ReportConnectionString").ConnectionString)
Dim cmd As New SqlCommand()
cmd.Connection = conn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "sp" & Request.QueryString("reportname") ' Build stored procedure string from an example query string
Dim sqlAdapter As Object
Dim dt As Object

' Depending on what report you want to display, you'll need to call the right table adapter, hence why they are defined as objects at first
sqlAdapter = New DataSet1TableAdapters.[NameDefinedInDataSet1]TableAdapter()
dt = New DataSet1.[NameDefinedInDataSet1]DataTable

sqlAdapter.Fill(dt)
conn.Close()

Dim Source As New ReportDataSource("DataSet1_[NameDefinedInDataSet]"), dt)
ReportViewer1.LocalReport.DataSources.Add(Source)
ReportViewer1.LocalReport.ReportPath = "Report.rdlc"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Now if you followed that jumbled piece of code, congrats. If you're smart you'll have the name defined in the data set match up to the report name so you can use the query string (or whatever other method). You'll still need a case statement or bunch of if's for defining the sqlAdapter and dt. Also, the ReportDataSource will be looking for the specific DataSet1_[NameOfTableAdapterDefinedInDataSet].

If you are thinking what on earth?, so am I. Hence why we decided to stick with the Reporting Service Project even though the project will need to be seperate and can only be done in Visual Studio 2005.

Cheers, I'm out, and I do not want to think about this again until reporting improves for Visual Studio 2008.

Wednesday, July 23, 2008

Prereq

To install PerformancePoint Add-In for Excel, windows needs the following installed:

ADOMD.NET 9.0 SP2
http://go.microsoft.com/fwlink/?LinkId=93296

Analysis Services 9.0 OLE DB Provider (SP2)
http://go.microsoft.com/fwlink/?LinkId=93298


Or rather, in order to connect to a cube in asp.net, the above providers might be helpful.

Monday, July 21, 2008

Setting up WCF web service

While setting up a new project I ran into the following issue with a WCF web service that needed to pass data to a silverlight application.



The type of errors I was recieving:

Content Type application/soap+xml; charset=utf-8 was not supported by service


System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior contract: CubeService ----> System.Runtime.Serialization.InvalidDataContractException: Type 'GraphDataClass' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.


The problem is with the class contracts not matching and being unable to be serialized (or something along that effect)

Start by including
Imports System.Runtime.Serialization
-for examples [http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.aspx]

Give the class and properties the according contract information (See image below or example above)



That should allow you to add the WCF as a web service reference/fix the errors. Comment if you have questions on it, because I'm just briefly going over the problem/solution.

Friday, July 18, 2008

Silverlight: Beware of the Contract

WCF webservice in a silverlight project debugging.


Project build will succeed with 1 warning:

Warning 1 Custom tool warning: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.


This warning refers to the file Reference.svcmap Line 1 Column 1.


When you do run the project you will get:

The remote server returned an unexpected response: (404) Not Found.


This is a pretty good indicator that the web service is not being found. Why? It's looking in the wrong place of course. This is the second time that ServiceReferences.ClientConfig has caused me problems. The solution to resolve the above errors is to simply open up the ServiceReferences.ClientConfig in you Silverlight application, and point the to the correct location of your webservice. Last time I had my project open, the service was running on port 1786, now the port changed to 1408, thus an entirely different location.



Another place to look is under the Web.config file in the website project. Look for all the endpoint addresses, and check to make sure they are correct.
Hope this post helps your debug! Cheers

Wednesday, June 04, 2008

Ann Arbor Give Camp

Word on the street is that there is an Ann Arbor Give Camp on July 11-13, 2008 at Washtenaw Community College in Ypsilanti Michigan. Right now I'm not sure if I'll be able to go, but if I can, I may bike up and program some code for some charity. Check it out!


Oh and the Red Wings won the Stanley Cup if you didn't already know.

Tuesday, April 15, 2008

ASP.NET Memberships and Roles

Excellent source of information for memberships and roles in asp.net:
http://weblogs.asp.net/scottgu/archive/2006/02/24/438953.aspx

It helped me move my membership and roles database from a mdf file to a sql database.