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

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

from: (this is 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" /> 
+6
source share
1 answer

You yourself answered, except that you are looking for UrlEncode . You also need to confirm which asp:QueryStringParameter Type="DateTime" format accepts, for example. it may require MM/dd/yyyy HH:mm:ss regardless of the settings of the web server region, or it may be that it depends on the settings of the web server region, in which case you need a date format such as yyyy-MM-dd HH:mm:ss .

Update
Here is 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 format specifier ("o", "o")

+12
source share

All Articles