Category Archives: developing

Html.EditorFor

creating html stuff with asp.net mvc i really easy… thanks to the htmlhelper class… for example to create a input box:

@Html.EditorFor(model => model.Name)

this line of code renders the <input>-tag, with set value, name… based on the models attribute… so if its a string it renders a textbox… it its a bool, it renders a checkbox… this checkbox is rendered a little bit special, because there is always a hidden filed set false… i think this is needed to return always a value for the checkbox, even if its not checked… sounds great, but the result must be checked differently:

active = (collection[<checkboxName>].Contains(“true”) ? true : false);

Its a really cool helper… but has a really big problem… Html.EditorFor is currently not able to set a class… there for desinging the input fields is hard… for a textbox it renders class=”text-box single-line”… so simply add these to your css file… works good, but with a company wide stylesheet its kinda crap…

asp.net mvc

at work i needed to create a new web frontend… and actually i am really disapointed with microsoft web framework asp.net… for me it is too random… ok i dont know how to do it correctly, but i am really confused with the 32452390918745 events, which will be called every postback (postback? never thought in java, that there might be different types of postback… and handlers…)… but yeah… did some application with asp.net and they all work… and are running… i think… 🙂

new project. new technology: asp.net mvc. i like it… the concept is as stated in the name: mvc… and actually i think it is really good implemented and totally included into visual studio… simple create a controller… based on it create views and of course use the model… the where is my model thing is for me not yet 100% clear… when using a external project/dll… is the dll the model? or is the dll only the functionality for the controller to fill the model? or is the model a wrapper around the dll? currently using a bit of all possibilities… works, but fareaway from perfect…

ms sql timeout

ok we had a problem on an application… it was really slow and sometimes it resulted in a sql timeout. so sql server(MSSQL 2008 R2) must be slow… no wasnt… network must be slow… no wasnt… app server must be slow… no wasnt… app must be slow… good point… but isnt…

after reading and debuging the sourcecode(code was not mine and coder is on vacation(as usual, when problems pop up…)) the slow sql statement was a view… running the view in the ms sql management studio: instant… hmm… wtf? after a few more tests we figured out, that the problem is based on the sql servers client, and a little bit of randomness…. running the statement on the sql server was instant… running it locally on a computer 23 seconds!.. running it on a virtual maschine, on the same computer… instant… wth? and always in ms sql management studio…

after a few more tries, we saw, that the result of the viw is unsorted… adding a “order by” resulted in the same process speed on all boxes… WTF? but yeah… its the damn solution…

X-UA-Compatible

i had a problem with my super simple asp.net site… designed in locally with style sheets and looked cool 🙂 but after putting it on the IIS7 it looked completly different… wtf? after trying everything, renaming stuff, reconfigure the IIS, swear a lot… i found:

<meta http-equiv=”X-UA-Compatible” content=”IE=100″ />

ok it didnt really help, put it is the solution… 🙂

the X-UA-Compatible defines the render version browser of given website… so if IE=7, every newer browser tries to render the website with the IE7 rendering mechanism… every older browser renders it with its own rendering mechanism… so if set to 100 the browser renders it with his mechanism… as long as Microsoft doesnt release the IE101, when i hopefully do not create html anymore… …

but the meta-tag was not the solution in my case… IIS7 stores the X-UA-Compatible localy for every application… which can be set on the IIS7 in the http-header… that was the solution 🙂

read more

format in visual studio

simply

Crtl+K, Ctrl+D

nant timestamp

i needed a datretime to backup my deployed applications. the goal was to store the backup in a datetime named folder, so its easy to find the last backup.

tryed it with datetime::now() and other datetime functions, but wasnt really satisfied and acutally the nant code was kinda unreadable… so googled it… and tstamp is the solution

 <tstamp property=”backup.datetime” pattern=”yyyyMMdd_HHmmss” />

creates the wished for property… well done 🙂

ms office docx format

currently working on a c# document creator. main goal is to create new word documents, based on a template and input data…

so had to read stuff about the docx format and figured out pretty quickly, that the format is xml based… cool… but its way more better…

just ads “.zip” to a word document and open it…

read more: http://msdn.microsoft.com/en-us/library/aa338205(v=office.12).aspx

c# unit testing

I thought, after using nant, it is time to use unittests in my c# code. The main idea was to try out test driven implementation methods for my next, small project.

Ok asked google about how to implement unit testing in my maschine… how was it called? NUnit? ok found something different and im really proud on microsoft… a unit testing framework is include to Visual Studio 2010… and its really easy…

Crossread the following link and understood it: http://www.dreamincode.net/forums/topic/108976-c%23-unit-testing-basics/

compile projects with nant

compiling c# projects in visual studio is kinda easy… in nant it sould be to… after trying to build the whole solution, and reading the manual properly, <solution> can only be used with visual studio version 2002 and 2003… crap…

okt tryed it with <exec> and msbuild.exe… works 🙂 but then i figured outm that nant CAN compile projects… so back to the <solution>

<solution configuration=”debug”>
    <projects>
        <include name=”project.csproj” />
    </projects>
</solution> 

so this call opens the project.csprojfile and executes it… but normaly it throws an exception… this link provides the answer… just change the $(MSBuildToolsPath) to $(MSBuildBinPath)

so compiling projects with nant is easy 🙂

installing nant

first of all, i have no clue about visual studio and deployment… mainly i just compile it, then copy paste it. and yeah, that is really a bad way to do that… so i tought, why not simple use my old beloved ant? ok i know maven is the thing now to use, but i just need simple scripts to copy/deploy stuff… so nant will do, or have to…

  1. download: http://nant.sourceforge.net/ 
  2. install: Installation Manual

this is it 🙂 ok currently its only usable as a command line, but its working 🙂 if i am able to write scripts is something completly different…

on the other hand visual studio should be able to execute these kind of scripts… ok finding a tool was hard, but there is one: NAntAddIn

installing it on a Visual Studio 2010 is not really trivial, but with link its easy…

  1. copy the addin to the user addin folder: \My Document\Visual Studio 2010\Addins
  2. important: set the Visual Studio version to 10.0 in the NAntAddin.AddIn file
  3. now it can be added in the Visual Studio AddIn manager
  4. configure it to the nant.exe and its runable

i had to restart the visual studio, because the NAntAddIn did not print stuff in the output window. worked afterwards

so NAnt is now up and running… we will see, how it can be used by my mighty hands… 😛