|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Routing;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Page.MetaKeywords = "Test keywords";
Page.MetaDescription = "Test description";
if (!IsPostBack)
{
string test = Page.RouteData.Values["Name"].ToString();
txtData.Text = test;
if (!string.IsNullOrWhiteSpace(test))
{
txtData.Text = test;
divVal1.InnerHtml = OptionalPara(1, Val2: "Named Val 2", Val1: "Named Val 1");//named type order is changed
divVal2.InnerHtml = OptionalPara(2, Val2: "val2");
divVal3.InnerHtml = OptionalPara(3);
}
else
{
txtData.Text = "Parameter appears to be blank :)";
}
UseDynamic();
UseIsNullorWhiteSpace();
}
}
protected void btnBack_Click(object sender, EventArgs e)
{
Response.Redirect(ResolveUrl("~/MySecondPage/") + "An");
}
public string OptionalPara(int a, string Val1=null, string Val2 = null)
{
string newVal=string.Empty;
if (!string.IsNullOrWhiteSpace(Val1) && !string.IsNullOrWhiteSpace(Val2))
newVal = "a= " + a + ", Val1= " + Val1 + ", Val2= " + Val2;
else if (!string.IsNullOrWhiteSpace(Val1))
newVal = "a= " + a + ", Val1= " + Val1;
else if (!string.IsNullOrWhiteSpace(Val2))
newVal = "a= " + a + ", Val2= " + Val2;
else
newVal = "a= " + a;
return newVal;
}
public void UseDynamic()
{
dynamic intValue = 1;
dynamic strValue = " is my roll no.";
dynamic result = intValue + strValue;
divUseDynamic.InnerHtml = result;
}
public void UseIsNullorWhiteSpace()
{
bool stEmpty = string.IsNullOrWhiteSpace(string.Empty); //true
bool stReguSpace = string.IsNullOrWhiteSpace(" "); // true
bool stChar1 = string.IsNullOrWhiteSpace("\n\t"); //true
bool stChar2 = string.IsNullOrWhiteSpace("\r\n\v "); //true
bool stNull = string.IsNullOrWhiteSpace(null); //true
bool stData = string.IsNullOrWhiteSpace("Test String"); //false
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I have keen interest in learning new things, exploring more on a topic and being more versatile