ASP.NET : MVC or WebForms ?

by Rod
21. March 2010 03:24

With Asp.net MVC 2’s launch, I’ve been more and more curious on MVC, problem is I’m a used Web forms developer.

So started doing more research on what’s best to be oriented in etc..

And found this really interesting article with SWOT analysis :

http://blog.gadodia.net/choosing-between-webforms-and-mvc/

Tags: ,

asp.net

WP7 - Blend : Twitter Client Design WP7 with Blend (Basic)

by Rod
21. March 2010 02:06

In the first post I did for WP7, I showed how to develop a simple, mini Twitter client with VS 2010 RC.

This post is going to be designer oriented (beginner level, as if you’ve never used Blend before!)

In order to be able to use Blend for WP7, check out this site : http://www.silverlightshow.net/news/Expression-Blend-4-for-Windows-Phone.aspx

Now let’s get to the fun part.

In the designer window, right-click the "Update Status” button > Edit Template > Create Empty.

Name the template whatever you want, I’m calling it :”HotButton”.

post

Change the layout container of the new template from “Grid” to “Border”.

post1

Now let’s start designing :

Set the BorderThickness and CornerRadius to whatever you want.

In order to find the Properties faster you can use the Search bar.

post3

post4

Apply a gradient background by selecting the Background property and then picking the Gradient brush option.

And pick the colors you want from the palette.(left : start point , right : end point ).

post5

Now let’s add the text for our button.

Go to the “Assets” tab then Controls > double click on TextBlock (while insuring the Border layout container is still selected)

post6

 

Now let’s align our text, because we have to admit it is ugly on the left, so let’s change both “VerticalAlignment” and “HorizontalAlignment” Properties.

post7

Now go to the Foreground property of the TextBlock and set a foreground color, in my case it’s going to be something close to black.

post8

Mmmm what’s missing now ?

We have to link the Text property to the actual content of the Button. So to do that, click on the tiny square next to the Text Property > Template Binding > Content.

post9

And here you go, now let’s run our application. (Note : Blend will ask you if you want to run the application on the emulator or a device, be sure emulator is selected)

post10

That’s of course not everything you can do, we can change the Textbox, add some animation etc..

I’ll cover the animation in another post, stay tuned!

Tags:

WP7

Windows Phone Emulator 7 unlocked.

by Rod
20. March 2010 03:10

As usual when you give a cool toolkit; specially if the emulator is locked…people will want to have more ;) ..

Here’s a way to unlock the WM7 emulator (and a couple of pics) :

http://geeksmack.net/microsoft/1160-windows-phone-7-emulator-unlocked-with-a-little-hack

REMINDER : THIS IS NOT THE REAL FULL VERSION OF THE OS like we’ve seen in MIX.

Tags:

WP7

WP7 - DOTNET : Twitter Client for Windows Phone 7 with Silverlight

by Rod
16. March 2010 21:55

This tutorial is going to be a special one; As you all know : windows phone 7 sdk came out really moments ago..

And guess what ? it supports Silverlight and XNA for heavier gaming.

So what does this mean?..This means all .NET developers are really really happy.

Here’s a tutorial of how to build a TINY – MINI -Demo Twitter client (in silverlight!) on windows phone 7. (we’ll be satisfied by just updating the status :) ).

The SDK can be downloaded here : http://developer.windowsphone.com/

Install the SDK (very easy to install to advanced set up needed).

After the SDK install is completed, open Visual Studio 2010 RC or Visual Studio 2010 Express RC.

Create a new project > select the tab Silverlight for windows phone > Windows Phone Application and name your project whatever you want.

post1

Notice after the project creation, a cute design is already laid out.

Now let’s just change the 2 TextBoxs in MainPage.xaml (this is where your first window is set by default) text just to have something familiar to the application context :

<Grid x:Name="TitleGrid" Grid.Row="0">
            <TextBlock Text="Twitter Client" x:Name="textBlockPageTitle" 
Style="{StaticResource PhoneTextPageTitle1Style}"/> <TextBlock Text="Status" x:Name="textBlockListTitle"
Style="{StaticResource PhoneTextPageTitle2Style}"/> </Grid>


Launch your application now, the project is built and deployed to the phone emulator automatically.

And you should have something like this :

post2

 

Get back to your project, in order to stop debugging just press SHIFT + F5 ( NO NEED TO CLOSE THE EMULATOR, SAVES YOU A LOT OF TIME)

Now let’s add a textbox + a button

For best design / layout results we’ll add another row definition, so all of our rows definitions look like this now :

 <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
 </Grid.RowDefinitions>

Then we’ll add the Textbox and the button in the Grid called “ContentGrid” (already defined)

     <Grid x:Name="ContentGrid" Grid.Row="1">
           <TextBox Grid.Column="0" Name="txtStatus"
FontSize="{StaticResource PhoneFontSizeExtraLarge}"/> <Button Grid.Column="1" Name="btnUpdate" Content="Click Me"
HorizontalAlignment="Right" Padding="4" Click="btnUpdate_Click" /> </Grid>

You might notice the textbox is under the button and the layout isn’t that nice. So adjust manually with margins or with column definitions (or both).

Here’s an example :

<Grid x:Name="ContentGrid" Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
                <TextBox Name="txtStatus" TextWrapping="Wrap" AcceptsReturn="True" 
FontSize="{StaticResource PhoneFontSizeExtraLarge}" Height="262" Grid.Row="0" /> <Button Name="btnUpdate" Content="Update Status"
HorizontalAlignment="Center" Padding="4" Click="btnUpdate_Click" Grid.Row="1" Width="287" /> </Grid>

We end up with something looking like this :

post3

Now let’s get to the coding part :

First of all we have to add an event on the Button click; VS does it for us automatically by double clicking on the button.

So when the button is clicked we want to update our twitter status with the text that was entered in the textbox :

I’m using an HttpWebRequest here BUT there’s a ton of ways to do this, you can use already written librairies etc..

private void btnUpdate_Click(object sender, RoutedEventArgs e)
  {
      HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://twitter.com/statuses/update.xml?status=" + txtStatus.Text);
      req.Method = "POST";
      req.Credentials = new NetworkCredential("youusername", "yourpassword");
      req.ContentType = "application/x-www-form-urlencoded";
      req.BeginGetResponse(new AsyncCallback(GetResponseCallback), req);
  }

As you might of noticed the username, and password is written in the code behind, that’s not at all the best practice : the best practice would be to use OAuth (with consumer and secret key ) ..therefore no need to use username and password.

For simplicity / demo reasons we’re just going to stick to this method ;) .

The BeginGetResponse method that I call at the last line of is to begin an Asynchronous request to the internet resource, so in our case twitter (why asynchronous you might ask ? so the application doesn’t just freeze while the request is made)

And now add the following code for the GetResponseCallback method :

private static void GetResponseCallback(IAsyncResult asynchronousResult)
    {
        HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
        HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
        response.Close();
    }

For more  information about using HttpWebRequest and its methods check msdn!

Now run the whole thing!

post5

 

TADAAM!!..

To take this further, an ideal thing is to build a real client, getting the friends timeline to show them in a list, adding RT and replies and Direct messages etc..

Good coding and hope you liked this tutorial!

Who said we need seesmic??! :p

Tags: ,

WP7

Disable button focus on a blackberry application (Java)

by Rod
15. March 2010 01:12

As a usual .net developer, I’ve been used and spoiled with various methods that are real time savers!

And to be honest while developing a blackberry application I’ve come across a lot of things that need a bit more of work in the Blackberry Java SDK.

Let’s say you want to disable a button on your application and not permit the button selection.

You see you can enable/disable the focus on the button, but you can enable / disable the button to be clicked/

So how do you disable the selection?

You might be satisfied by just removing and re-adding the button into the UI.

But here’s a simple way to overcome this small obstacle :

First of all you need to create a new class that extends from “ButtonField” :

   1:  public class MyCustomButton extends ButtonField 
   2:  {
   3:  }

After adding the constructors you need, you have to override isFocusable method :

If my button is disabled I don’t want it to be focusable so we’d return the isEditable() method.

So the class right now looks like this :

   1:  public class MyCustomButton extends ButtonField 
   2:  {
   3:     public MyCustomButton()
   4:      {
   5:          super();
   6:      }
   7:   
   8:      public MyCustomButton(long style)
   9:      {
  10:          super(style);
  11:      }
  12:   
  13:      public MyCustomButton(String label)
  14:      {
  15:          super(label);
  16:      }
  17:   
  18:      public MyCustomButton(String label,long style)
  19:      {
  20:          super(label,style);
  21:      }
  22:   
  23:      public boolean isFocusable()
  24:      {
  25:          //this is where all the magic happens.
  26:         //if my button is disabled then i don't want it to be focusable
  27:          return isEditable();
  28:      }
  29:   
  30:  }

So in order to disable our button right now and disable the focus all we have to do is call the setEditable() method and send false in parameter.

   1:  MyCustomButton btnHello = new MyCustomButton();
   2:  btnHello.setEditable(false);

Tags: ,

general development

ASP.NET : Change CSS from code behind.

by Rod
12. March 2010 13:40

A student/colleague of mine, after checking out a site I did, asked me: how do you change CSS files dynamically?

The answer is very simple;

I’m using a master page here and usually in the head container there’d be your css link;

By adding ‘runat=”server”’ and giving it a unique id you make the link run server side, and then after that modifying the ‘href’ attribute is done in the code behind.

 

<link id="masterCss" href="App_Themes/Theme1/yourcssfile.css" type="text/css" rel="stylesheet" runat="server" />

Then in the code behind :

masterCss.Href = "App_Themes/Theme1/secondcssfile.css";

Clearly that would be best set up in : “Page_Load” event or “Page_PreRender” depending on your needs :).

Tags:

asp.net

ASP.NET 4: View State

by Rod
5. March 2010 01:36

 

As web developers we’ve all had our fair share of view state, while trying to minimize them / storing them in a database or even disabling view state for some controls one by one.

When there’s more View state then we need, we lose a lot in performance. (+ not all search engines like itL)

In previous versions of asp.net, view state was enabled by default on pages therefore we had to disable view state on the controls 1 by 1.

Well guess what??

No more CTRL + C EnableViewState="false"  AND CTRL + V 1000xx times.

Now it’s possible to simply disable View state on a whole page and just enable it on the controls we want.

Here’s an example:

My page contains 1 button and 1 label, and here’s my view state :

value="/wEPDwUKLTU2ODgwMzc3NWRkf86Sf4W2JXJIMUDuy2TW5uSqft0zrNjXFhCnQ7cjfZ8="

By clicking the button (set to change the label text), the View state gets even bigger.

Now by disabling the view state on the whole page by setting ViewStateMode attribute to “Disabled” on the page directive:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" ViewStateMode="Disabled" %>

 

My view state stays the same size.

As you might have expected, the label doesn’t preserve its value since its view state is also disabled, so your choice to choose which controls you need to enable view state on.

Tags: ,

asp.net

Blog O' coding

by Rod
4. March 2010 21:38

Dear readers, this might be a bore for the usual readers.

But today is an important day for the blog!

As I applied to be a Microsoft Student Partner, and I’m studying in order to pass the .net 4 beta certifications:

My blog will start getting a coding prospect.

Basically there’ll be a “personal” category, it will contain all the previous posts + the new ones about motivation / challenge etc..

And other categories that I'll use to post about Silverlight / SharePoint / .NET 4 and maybe some about mobile development ;)

 

Visual Studio 2010

Tags:

Choices you make.

by Rod
26. December 2009 00:17

Whether its business or pleasure, you always find yourself in situations where a decision has to be made.

Sometimes some of these situations are life changing events; so when you do realize a lot of things are changing you ask yourself: “mmm what would of happened if I did “something else” instead? “

Suddenly you’d doubt yourself and you’d forget the reasons why’d did you do it!

But reminding yourself why you did it; is what will make you move forward.

I recently dealt with a major situation where my decision would mutate the rest of my career life; the decision was about whether I needed to change jobs or not, to seek new opportunities, to learn new things and finally to find different kind of challenges.

When hitting a tough point and feeling lost, I doubted myself on whether my decision was the right one or not.

This can also happen on a personal note:

I’ve decided this year to spend this winter vacation on my own instead of going back home; so I can stay focused on work.

When I hit a down turn (last night); realize I’m actually spending Christmas Eve away from family, I forgot what were the reasons that made me stay here.

I felt sad about it until I finally reminded myself why I’ve made this choice.

I promised myself not to forget why I’ve made the choices I made, in order to be able to move on without any regrets!

The conclusion didn’t turn out like I’ve hoped for, oh well…you got the point!

Tags:

Personal

Merry Christmas!

by Rod
25. December 2009 02:26
Merry Christmas

Tags:

Personal

Rodrigue Hajjar

About the author

.NET Developer.

.Supinfo Student.

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar