For those who don't know, the base samples show a scenario in which the 'Submit' button on the first page has it's PostBackURL property assigned to the second page in the postback scenario. The code, then would look something like:
As we stated earlier, if you're using a Master Page in your website (with a Master Page designated, specifically, in the submitting page), this doesn't work. In able to do this, you must look in the Content Placeholder of the submitting page, first. Therefore, the code would look more like this:Dim Name As TextBox
Name = Page.PreviousPage.FindControl("txtName")
Label1.Text = Name.Text
In this sample, we first look inside the submitting page, then we find the Contentplaceholder. Then, once we find the contentPlaceholder, we look inside it, to find the control, from which we need to retrieve the data. Here's a small function which does all this for us, to cut down on repetitive code:Dim ph As ContentPlaceHolder = CType(PreviousPage.Master.FindControl("YourContentPlaceholderID"), ContentPlaceHolder
Dim tb As TextBox = CType(ph.FindControl(YourControlID), TextBox)
Label1.Text = tb.Text
Then, to use it, you merely do something like this:Function GetData(ByVal CtrlID As String) As String
Dim ph As ContentPlaceHolder = CType(PreviousPage.Master.FindControl("YourContentPlaceholderID"), ContentPlaceHolder)
If Not ph Is Nothing Then
Dim tb As TextBox = CType(ph.FindControl(CtrlID), TextBox)
If Not tb Is Nothing Then
Return tb.Text
End If
End If
Return String.Empty
End Function
That's all there is to it. Have fun!lblName.Text = GetData("txtName")
No comments:
Post a Comment