Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to encode a DateTime in a QueryString and read it in the asp:QueryStringParameter

Tags:

c#

asp.net

vb.net

How to encode a DateTime in a QueryString and read it in the asp:QueryStringParameter?

out: (it's a asp:HyperLink NavigateUrl)

String.Format("~/Reports/Logs/Option_History.aspx?OptionID={0}&time={1}", _
              id, _
              time)

in:

<asp:QueryStringParameter Name="time" 
                          QueryStringField="Time" 
                          Type="DateTime" 
                          ConvertEmptyStringToNull="true" />
like image 747
DavRob60 Avatar asked Mar 17 '10 20:03

DavRob60


1 Answers

You've answered it yourself, except you're looking for UrlEncode. You also need to confirm what format asp:QueryStringParameter Type="DateTime" accepts, e.g. it may require MM/dd/yyyy HH:mm:ss irrespective of the region settings of the web server, or it could be that it is dependent upon the region settings of the web server, in which case you need an invariant date format like yyyy-MM-dd HH:mm:ss.

Update
Here's a working example:

String.Format("~/Reports/Logs/Option_History.aspx?OptionID={0}&time={1}", _
              id, _
              HttpUtility.UrlEncode(time.ToString("o")))

ToString("o") converts it using The Round-trip ("O", "o") Format Specifier

like image 118
Mark Hurd Avatar answered Oct 21 '22 07:10

Mark Hurd