Reputation: 4864
Is it possible to take the value from a string variable from a code-behind file and display it in this markup?
<h1>People Authorized to Release Children for <TheVariableGoesHere> </h1>
The variable we would like to include is called strForename.
Protected Sub GridViewParentsSummary_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridViewParentsSummary.SelectedIndexChanged
IntParentsID = GridViewParentsSummary.DataKeys(GridViewParentsSummary.SelectedIndex).Value
strForename = GridViewParentsSummary.DataKeys(GridViewParentsSummary.SelectedIndex).Values("Forename")
blnAddModeIsSelected = False
Response.Redirect("AuthorizationForChildReleaseDetails.aspx")
End Sub
Upvotes: 3
Views: 5592
Reputation: 1907
You can do this by making your variable protected or public member and using it in the markup like this:
<%#strForename%> Make sure to call DataBind so the field is bound. I see that you are doing a redirect at the end of your function, You cannot use the variable from page 1 into a redirected page unless you pass it somehow (as a Request parameter or session parameter) Alternatively you can do a Server.Transfer and pass that in the context
Upvotes: 2
Reputation: 47189
The way this would be accomplished is through a code behind method being called.
Something like this for C#
<h1>People Authorized to Release Children for <% =this.GetForename() %> </h1>
or this for VB.NET
<h1>People Authorized to Release Children for <% =Me.GetForename() %> </h1>
and in code behind C#
protected string GetForename()
{
return GridViewParentsSummary.DataKeys(GridViewParentsSummary.SelectedIndex).Values("Forename");
}
or in VB.NET
Protected Function GetForename() As String
Return GridViewParentsSummary.DataKeys(GridViewParentsSummary.SelectedIndex).Values("Forename")
End Function
Upvotes: 4