Archive

Archive for the ‘c#’ Category

ASP.NET QueryExtender RangeExpression

February 28th, 2011 No comments

The RangeExpression takes two parameters – one for min and one for max. This wasn’t clear to me at first. Consider:

<asp:RangeExpression DataField="ListPrice"
MinType="Inclusive" MaxType="Exclusive">
<asp:ControlParameter ControlID="FromTextBox" />
<asp:ControlParameter ControlID="ToTextBox" />
</asp:RangeExpression>

FromTextBox is the minimum value.

ToTextBox is the maximum value.

Categories: ASP.NET, c#, DynamicData Tags:

Programatically adding an error message to a ValidationSummary

February 27th, 2011 No comments

Found this info here. Great post!

In essence…

public class ValidationError : IValidator
{
    private ValidationError(string message)
    {
        ErrorMessage = message;
        IsValid = false;
    }
 
    public string ErrorMessage { get; set; }
 
    public bool IsValid { get; set; }
   
    public void Validate()
    {
        // no action required
    }
 
    public static void Display(string message)
    {
        Page currentPage = HttpContext.Current.Handler as Page;
        currentPage.Validators.Add(new ValidationError(message));
    }
}

ValidationError.Display("Oops, some error occurred.");
Categories: ASP.NET, c#, web development Tags:

ASP.NET 4.0 Dynamic Data : Foreign Keys show up in a Text Box

February 27th, 2011 No comments

And then when you add the UIHint=”ForeignKey” you get this exception:

'XXX' is not a foreign key column and cannot be used here.

The trick is to not use the name of the foreign key column but rather the name of the auto generated navigation mechanism as mentioned here. I had trouble finding this at mechanism at first, but then realized it defaults to the name of the foreign key from the database.

Hope this saves someone the heartache!

Categories: ASP.NET, c#, DynamicData Tags:

Roles.AddUserToRole will create a user

February 7th, 2011 No comments

if the user doesn’t already exist.  I incorrectly assumed that it would return an error indicating the user didn’t exist.

Categories: ASP.NET, c# Tags:

xs:description

January 18th, 2011 No comments

I’m working with a client who has very detailed information buried within an XSD xs:description elements.

After much digging, I found this XSLT stylesheet which will pull out the descriptions into a nice web page.

I just whipped up a quick web page to display the results:

    void Page_Load(object sender, System.EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(Server.MapPath("my.xsd"));

            XslTransform xslt = new XslTransform();
            xslt.Load(Server.MapPath("xs3p.xsl"));

            MemoryStream ms = new MemoryStream();
            xslt.Transform(doc, null, ms);
            ms.Seek(0, SeekOrigin.Begin);

            StreamReader sr = new StreamReader(ms);
            //Print out the result
            Response.Write(sr.ReadToEnd());
        }
    }
Categories: ASP.NET, c#, visual studio Tags:

JSON from .NET to iOS devices

December 20th, 2010 No comments

I’ve been struggling with the built in JSON serializers in .NET. I’m using .NET on the backend to generate a JSON file to be consumed on an iOS device. The deserialization on the device will be done via SBJson (which is included with iOS Facebook connect).

JavascriptSerializer is quick and dirty as I didnt have to decorate my objects with DataContract and DataMember. However, it includes the string null for objects which are null. SBJson reads those as the string “null” which isn’t what I wanted.

I then turned to DataContractJsonSerializer. This didn’t produce the ‘null’ strings but it would require me to decorate all my classes and members which I didn’t want to take the time nor create the maintenance task of remembering to do this.

So I found JSON.NET. In about 20 minutes I had it installed, running and not spitting out the null values. A great find!

Thanks!!

Categories: ASP.NET, c#, Facebook, iOS, javascript Tags:

Monoreports Sounds Interesting

December 12th, 2010 No comments

I’m going to have check out this new report designer which uses a code behind file. Monoreports

Categories: ASP.NET, c# Tags:

Creating dummy data for System.Data.Linq.Binary

December 1st, 2010 No comments

I was filling in some test case data and wasn’t sure how to fill in System.Data.Linq.Binary.

Thanks to this post for helping!

Categories: c#, LINQ Tags:

Subclassing LINQ to SQL classes doesn't work

December 1st, 2010 No comments

I tried to created a Data Access Layer but subclassing the autogenerated classes from LINQ to SQL in .net 4.0. All was going fine until I tried to InsertOnSubmit () with the derived class. NULL Exception. After spending some time trying to overcome the problem, i decided that this is a deficiency in with LINQ to SQL and cannot be accomplished. I wonder if Entity Framework 4 has this problem. I wish I had time to investigate but, for now, I’m just including the generated class as a property in the DAL class and have moved on.

Sigh.

Categories: c#, LINQ, SQL Tags:

Keeping Exception Stack Traces

December 1st, 2010 No comments

I knew I had read this somewhere…

Rethrowing C# Excpetions While Maintaining Stack Trace

Categories: c# Tags: