On the previous page, the user is going to click a button from a gridview. Each button click will produce a different result on the next page. I want to display text that will put information from a database into the header text. For example, if the user clicks the button next to the "03/04/2012 - 03/11/2012", I want the header on the next page to say: "Please enter data for 03/04/2012 - 03/11/2012".
Is this possible? Is this even recommended or am I better off using an asp:label control?
Yes, this is possible and perfectly acceptable.
Use an embedded code block (sometimes called gator tags) <%=...%>
in your markup. The =
operator is equivalent to calling Response.Write
, so it just outputs the value of whatever you give it inline.
<h2>Please enter data for <%=DateRange%></h2>
In this example, DateRange
would be a property on your next page. If you're getting this date range data from a database as you say, then you would need to store it when you click on the grid view button and then retrieve it on the next page.
There is nothing wrong with doing it like this, but storing it in a database seems like overkill just to get the value on the next page. You can use one of the following instead:
A quick google search turned up this page which shows examples of all of these methods.
Regardless of which method you use, gator tags can still be used to set the value of the H2 on the next page.
Also, if you are using Asp.Net 4, then you can use <%: %>
. It's Like <%= %>
But it HtmlEncodes the output automatically.
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