xVal provider for FluentValidation

by Magnus Bertilsson 2. May 2009 18:24

Yes finally I found someone who written a xVal provider for FluentValidation, you can find it at http://fluentvalidation.codeplex.com/Thread/View.aspx?ThreadId=54463 but you must download the sourcecode for fluentvalidation and compile it. So hopes it helps someone out there ;)

Tags:
Categories:

Javascript in my usercontrols at the bottom please

by Magnus Bertilsson 24. March 2009 16:22

So the other day I sat down to optimize my latest part of a page that I been working on and I realized that I had some javascript in a usercontrol. In the javascript I called .net functions like ResolveUrl and i didn't want the cost of yet another request with the thoughts of all my jquery plugins.

So what was my solution, well after a couple of bad ones I found a very smart one if I may say so myself :) I used one of my loves HtmlTextWriter and RenderControl.

 UserControl:


<asp:placeholder id="phr" runat="server">

<script type="text/javascript">......</script>

</asp:placeholder>

So I put my javascript in a placeholder in my usercontrol.

UserControl Codebehind:

protected void Page_Load(......) {

    var key = this.ID + "_script";
    var stream = new StringWriter();
    phr.RenderControl(new HtmlTextWriter(stream));
    phr.Visible = false;

    if (!Page.ClientScript.IsStartupScriptRegistered(key))
        Page.ClientScript.RegisterStartupScript(Page.GetType(), key, stream.ToString().Replace("\n", "").Replace("\r", "").Replace("\t", ""));

}

And here i render my placeholder to a string then hides it so it won't render at the usercontrols place on the page. Then i use the scriptmanager in a webform page, but you can build this in mvc / asp.net(without webforms) to without a scriptmanager and you minified the script with replace ;) This way you follow the yahoo tip to render javascript at the bottom of the page and in only one request.

I hope someone out there have use of this :)

Tags:
Categories: C# | Javascript

Nested linq queries

by Magnus Bertilsson 23. March 2009 18:41

So linq queries are something I like, but there was something I didn't knew how I should do a nested query. But a few days ago I saw an example of it so thought i should write something about it.

 

Exemple:

from item in list from subitem in item.SubItems select subitem

 

Hope somebody has use of this to :D

 

Tags:
Categories: C#

Hello World

by Magnus Bertilsson 23. March 2009 14:33

As for Jakobsson this is also my first blog post and I am a programmer through my whole heart and soul, which i think explains my headline. The Similarities between me an Jakobsson doesn't end there because I am also from the Varberg and we have gone to the same school and share the programming intrest.

So what is there to talk about except MVC the new big and fun thing out there to play with and I love it, But the biggest things about it, is not the MVC pattern. The things that are the most interesting from my point of view is the Routing. As you can see in the MVC FUBU project, because it's one of the things they kept. And i also love the binders they are going be very intresting to use :D I can't think of anything I don't like yet and i love that Microsoft opens up and share the source code.

So a really big thanks to the MVC team from me to :D

Tags:
Categories: General