[RESOLVED]Date in UrlString

Hey guys,

What is the best way to use the UrlString to input a date? I want to use that value from a form into another page..

Cheers!

You can pass the value from one page another page using the QueryString

Please see the sample implemenation

Your PageA.aspx

You can pass value to pageB like given below

protected void btnRedirect_Click(object sender, EventArgs e)
        {
            //Pass the datevalue as Query string
            Response.Redirect("YourPageB.aspx?PassingValue=" + "11/10/2014");
        }

YourPageB.aspx(Receiver Page)
You can read the value passed through query string like given below

  //Read the values from Query string
            string value = Request.QueryString["PassingValue"].ToString();

2) Using Session

An Easy solution is to use
Session
 and it will be like this

Your PageA.aspx

           //Set the value of Textbox to session
            Session["Data"] = "11/10/2014";
//Perform your Redirect Response.Redirect("YourPageB.aspx");

YourPageB.aspx(Receiver Page)

You can read values from session like given below

            if (!String.IsNullOrEmpty(Session["Data"].ToString()))
            {

                //Read values from session
                string valueA = Session["Data"].ToString();

            }

 

Response.Redirect("page.aspx?date=10112014");
        if (Request.QueryString["date"] != null)
        {
           DateTime dt = DateTime.ParseExact(Request.QueryString["date"], "ddMMyyyy", null);
        }

A2H

You can pass the value from one page another page using the QueryString

Please see the sample implemenation

Your PageA.aspx

You can pass value to pageB like given below

protected void btnRedirect_Click(object sender, EventArgs e)
        {
            //Pass the datevalue as Query string
            Response.Redirect("YourPageB.aspx?PassingValue=" + "11/10/2014");
        }

YourPageB.aspx(Receiver Page)
You can read the value passed through query string like given below

  //Read the values from Query string
            string value = Request.QueryString["PassingValue"].ToString();

2) Using Session

An Easy solution is to use
Session
 and it will be like this

Your PageA.aspx

           //Set the value of Textbox to session
            Session["Data"] = "11/10/2014";
//Perform your Redirect Response.Redirect("YourPageB.aspx");

YourPageB.aspx(Receiver Page)

You can read values from session like given below

            if (!String.IsNullOrEmpty(Session["Data"].ToString()))
            {

                //Read values from session
                string valueA = Session["Data"].ToString();

            }

 

I ended up just using the UrlString and put it on the format dd-MM-yyyy and it worked nicely but I might start using Session – Presumably it hides the string?

Leave a Reply