Tips and Tricks in a world of Mix

Archive for August, 2011

Why <% ; %> instead of <%= %> ?

 

One of the subtle things you might have noticed with the code above is that we are using a <% %> block instead of a <%= %> block when calling Html.RenderPartial().

<%= %> blocks in ASP.NET indicate that a developer wants to render a specified value (for example: <%= "Hello" %> would render "Hello").  <% %> blocks instead indicate that the developer wants to execute code, and that any rendered output within them must be done explicitly (for example: <% Response.Write("Hello") %>.

The reason we are using a <% %> block with our Html.RenderPartial code above is because the Html.RenderPartial() method doesn’t return a string, and instead outputs the content directly to the calling view template’s output stream.  It does this for performance efficiency reasons, and by doing so it avoids the need to create a (potentially very large) temporary string object.  This reduces memory usage and improves overall application throughput.

One common mistake when using Html.RenderPartial() is to forget to add a semi-colon at the end of the call when it is within a <% %> block.  For example, this code will cause a compiler error:

      <% Html.RenderPartial("DinnerForm") %>

You instead need to write:

      <% Html.RenderPartial("DinnerForm"); %>

This is because <% %> blocks are self-contained code statements, and when using C# code statements need to be terminated with a semi-colon.

 

 

source

Advertisements

Using Eclipse with Phonegap for VS projects – Solution

Let’s assume that we’ve installed all the needed software as described in :

http://wiki.phonegap.com/w/page/16494774/Getting%20started%20with%20Android%20PhoneGap%20in%20Eclipse

 

Now we open the Eclipse :

image

File –> New –> Android Project

now will add the project definitions

image

When you choose Android 2.2 automatically Min SDK Version defined as 8

Package should be with two parts – package name and project name

Next –> Finish

 

Open new folders libs and assets\www

image

 

 

Go to phonegap source  and get the phonegap.0.9.6 jar and js files.

image

jar goes to libs

js goes to assets\www

image

 

Now we’ll add the phonegap library to the project so:

Right click on jar file –> build path –> add to build path

image

Afterwards you can see the referenced library added to the solution :

 

image

Now we can reference it in code .

Go to src –> Pack.MyTest –> MyTestActivity.java –>

Add import and change extending :

Original Source:

package Pack.MyTest;

import android.app.Activity;
import android.os.Bundle;

public class MyTestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

 

Changed adding phonegap and extending from Droid and add the start page :

package Pack.MyTest;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.*;
import com.phonegap.*;

public class MyTestActivity extends DroidGap {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        ///add the start page
        super.loadUrl("file:///android_asset/www/index.html");
        setContentView(R.layout.main);
    }
}

Add to assets\www index.html start page as promissed :

image

(put the reference to phonegap.js inside)

 

Define the properties of the runner AVD :

image

image

Define what project you want to run :

image

Go to Right click MyTest –> Run as –> Android Application

 

image

 

Our Android application :

image

Go to your VS 2010 and open WebSite

image

 

Find your workspace for eclipse –> Open :

image

Work with VS – > JQM

image

Tag Cloud

%d bloggers like this: