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" />
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With