Saturday, February 28, 2009

Passing value from from contentplaceholder to masterpages

While I was developing a web application for tracking tasks/jobs among employees, I was having a problem to pass a value from pages in contentplaceholder to it's main masterpages. Since I was trying to adapt this new features of asp.net 2.0 of having masterpages as a replacement for it's "frame", it was difficult to understand for the first time on how this masterpages works.
After converting into masterpages

I want my left side menu to be on/off depending on the task. If the user had saved the task, then the next stage will be enable or else the user won;t be allowed to go into next level if he doesn't save the task.
Therefore, I need some indicator says that the task have been saved. I place one hidden value in that particular page. When the user clicks the button "Save", the value of hidden button will be "Saved". In the meantime, in masterpages code behind, I place a function to interate all the controls that available in contenplaceholder (after struggling google for an answers finally!), erm but before that, you need to add this
in your page before you go to the masterpages page.
sO, in the codebehind add this function to look for a control created in the contentplaceholder.
Function GetData(ByVal CtrlID As String) As String
Dim ph As ContentPlaceHolder = CType(Page.Master.FindControl("ContentPlaceHolder1"), ContentPlaceHolder) If Not ph Is Nothing Then Dim hidval As HtmlInputHidden = CType(ph.FindControl(CtrlID), HtmlInputHidden)
If Not hidval Is Nothing Then Return hidval.Value End If End If
Return String.Empty
End Function
..then in Page.Load event, I'll call this function, so that my disable link will be enable once the user clicks the save button in contentplaceholder page..taDaa!!!
If Page.IsPostBack = False ThenHidden1.Value=GetData(Hidden1.Value)
if hidden1.value<>"" then 'enable linkelse'disable linkend if
End If
Hope it helps!!

Thursday, January 15, 2009

:: Welcome partners!

:: this blog is created just to share some of our knowledge and expertise in some of the subject areas..

feel free to view and don't hesitate to drop a comment so that we can improve our services...


bYe

regards
-BNa Integrated