Monday, May 2, 2011

Breakpoints and Watching Variables in ASP.Net


In Visual Studio you can set a Breakpoint to stop the project at a particular line of code.
Once you set the Breakpoint to a line and you run the project, it will stop the project before executing the line and shows the particular line in the code editor.



To set a Breakpoint click the gray margin to the left of the line where you want to give a break.
The watch window opens only when the debugger is in running mode or break mode.
So open the watch window when the projects halts at the breakpoint through
Debug >> Windows >> Watch and select a watch window.




You can view the value of the variables by just pointing the mouse over the variable and also using the Watch.
If the variable is complex type like arrays or an object you should use the watch window.
To add the variables into watch window just select the variable and drag it to the watch window.
Click the + sign to view the subitems such as array elements or object properties.

Read more: http://csharpdotnetgallery.blogspot.com/2010/01/setting-breakpoints-and-watching.html#ixzz1LBq3TZdm
This article and source code demonstrates a technique for creating the tabbed page interface ('TabControl') shown below for an ASP.NET 2.0 web page.

The technique uses Visual Basic 2005, and the ASP.NET 2.0 MultiView, View, and Menu controls which are new in ASP.NET 2.0.




See the markup in the 'Default.aspx' web page (in the source code). There you will see how the Menu control, MultiView control, and View controls are defined.

The 'StyleSheet.css' file in the source code defines a very simple border which is shown below the 'tabs'.

For each 'tab' page there must be an enabled tab image, and a disabled tab image. See the 'Images' folder in the source code.

When a user clicks a tab (actually a MenuItem), the ImageUrl for the MenuItem associated with the tab is set to the enabled image for the tab. At the same time, all other MenuItem ImageUrls are assigned 'disabled' tab images. Shown below is the Visual Basic 2005 code that processes the interface when a user clicks a tab.

Code



Protected Sub Menu1_MenuItemClick(ByVal sender As Object, ByVal e As MenuEventArgs) Handles Menu1.MenuItemClick

MultiView1.ActiveViewIndex = Int32.Parse(e.Item.Value)



Menu1.Items(0).ImageUrl = "~/Images/HomeDisabled.jpg"

Menu1.Items(1).ImageUrl = "~/Images/ProductsDisabled.jpg"

Menu1.Items(2).ImageUrl = "~/Images/SupportDisabled.jpg"

Menu1.Items(3).ImageUrl = "~/Images/HelpDisabled.jpg"



Select Case e.Item.Value

Case 0

Menu1.Items(0).ImageUrl = "~/Images/HomeEnabled.jpg"

Case 1

Menu1.Items(1).ImageUrl = "~/Images/ProductsEnabled.jpg"

Case 2

Menu1.Items(2).ImageUrl = "~/Images/SupportEnabled.jpg"

Case 3

Menu1.Items(3).ImageUrl = "~/Images/HelpEnabled.jpg"

End Select

End Sub

Pass array through session between two pages

Page 1:

we can store an array into session.


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnSendData_Click(object sender, EventArgs e)
{
int[] inputdata;
string s=txtinput.Text.Trim();
string[] numbers = s.Split(',');
inputdata = new int[numbers.Length];
for (int i = 0; i < numbers.Length; i++)
{
try
{

inputdata[i] = Convert.ToInt32(numbers[i].ToString());
}
catch(Exception ex)
{
Response.Write("please enter data in integere formate separated by comma");
}

}
Session["IntArray"] = inputdata;
Response.Redirect("receive data.aspx");
}
}

Page 2


public partial class receive_data : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int[] RecArray=(int[])Session["IntArray"];
for(int i=0;i {
Response.Write(RecArray[i].ToString()+" ");
}
}
}