|
-
Aug 7th, 2009, 04:15 AM
#1
[RESOLVED] Master page postback
Hi guys i have a question, i'm try to get the value of a textbox control that placed inside a master page, i used this code for retrieving back the texbox values:
Code:
If Not Page.PreviousPage Is Nothing Then
search = TryCast(Master.Page.PreviousPage.FindControl("SearchPost"), TextBox)
If Not search Is Nothing Then
Response.Write("My Text: " & search.Text)
End If
Else
search = TryCast(Master.FindControl("SearchPost"), TextBox)
End If
Now, if I try to get the textbox value where i'm in the target page (the page that contain that cod) there is no problem.
but if i'm posting it from Page A to Page B (target page) i can't get the master page textbox control value.
any suggestions ?
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Aug 7th, 2009, 01:04 PM
#2
Re: Master page postback
Cast Page.PreviousPage to its actual type. (If previous page is Page9.aspx, then cast it to type Page9)
Then, look at its Master property and cast that to the type. So if Page9's Master page is called MasterPencil.master, then cast it to type MasterPencil. Then do a FindControl and look for the textbox.
-
Aug 7th, 2009, 03:09 PM
#3
Re: Master page postback
sorry for my ignorant, but how do i cast Page.PreviousPage to its original page (code wise) , i kind of new to asp.net
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Aug 7th, 2009, 03:15 PM
#4
Fanatic Member
Re: Master page postback
Something like
Code:
Dim test As Page = DirectCast((Page.PreviousPage), Page9) --There should be a page in your project called Page9.aspx
Dim previousMaster As MasterPage = DirectCast((test.Master), MasterPage)
-
Aug 7th, 2009, 03:21 PM
#5
Re: Master page postback
The name of that Page is "Default" and that seems to be a preserved word, what should i do now?
and i really don't understand why simple parameters posting needs to be so hard, isn't asp.net suppose to make life easier?
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Aug 7th, 2009, 03:57 PM
#6
Fanatic Member
Re: Master page postback
I didn't realize that could be an issue and I posted the code above just thinking about how to do a cast.
As for simplicity, the simplest way to pass values across pages are QueryString, Session (should be judiciously used), class properties etc. If you are trying to do a cross page posting with master pages I would suggest reading this article
-
Aug 7th, 2009, 04:10 PM
#7
Re: Master page postback
Thank you for your help rjv,
I made a small adjustment to the code you provide me and it work perfectly when posting from every page
Code:
Dim test As Page = DirectCast((Page.PreviousPage), Page)
Dim previousMaster As MasterPage = DirectCast((test.Master), MasterPage)
i changed the "Page9" to "Page" and now i can retrieve the value of the master page text box control from any page.
I will now read the article you provided and hopfully i when i done i'll be a little bit smarter in this subject.
Thanks.
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Aug 8th, 2009, 04:25 AM
#8
Re: [RESOLVED] Master page postback
It doesn't matter what the page is named, you simply need the class type. You'd get that from the codebehind, right at the top, at the class declaration.
But yes, you're getting yourself into an unnecessarily complicated situation; think about the purpose of this textbox, whether its value needs to be used throughout the app, and if it does, how you should be passing it around.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|