dejandejanovic
asked on
Not able to pass session value from parent page to UserControl. Need someone to check current codes!
Hello,
can someone please take a look of my codes, as not able to execute job base on session value, which should be passed from parent page to user control.
Parent code:
UserControl code:
can someone please take a look of my codes, as not able to execute job base on session value, which should be passed from parent page to user control.
Parent code:
Public Sub ButtonTest_Click(sender As Object, e As EventArgs) Handles ButtonTest.Click
Session("OpenDivOrder") = "True" 'Session
End Sub
UserControl code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim test As String = DirectCast(Session("OpenDivOrder"), String)
If test = "True" Then
divTest.Attributes.Add("style", "display: normal;")
End If
End Sub
ASKER
None error. And, no, I do not get value into UC. For example string Test from message is empty " ".
I'm also not sure how system does execute events. As you can see I have place code from UC into Load event. Maybe UC.Load is fired before parent button, or not?
I'm also not sure how system does execute events. As you can see I have place code from UC into Load event. Maybe UC.Load is fired before parent button, or not?
Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim test As String = DirectCast(Session("OpenDivOrder"), String)
MsgBox("message from UC:" + test)
If test = "True" Then
divTest.Attributes.Add("style", "display: normal;")
End If
End Sub
Hi,
As per your first post code.
When you click on button you are assigning the Session.
In UserControl Load() you are Checking for the Session.
When you want the value in User Control?
As per your first post code.
When you click on button you are assigning the Session.
In UserControl Load() you are Checking for the Session.
When you want the value in User Control?
ASKER
With words when click on parent Button, I want to display hidden DIV element from user control.
Hi,
try this code
try this code
Protected Sub Page_Load(sender As Object, e As System.EventArgs)
If Session("OpenDivOrder") IsNot Nothing Then
Dim test As String = Session("OpenDivOrder").ToString()
If test = "True" Then
divTest.Attributes.Add("style", "display: normal;")
End If
Else
Response.Write("Session is NULL")
End If
End Sub
Public Sub ButtonTest_Click(sender As Object, e As EventArgs)
'Session
Session("OpenDivOrder") = "True"
End Sub
ASKER
I guess I was need to put event ButtonTest_Click as
right, or?
<asp:Button ID="ButtonOpenDivOrder" runat="server" OnClick="ButtonTest_Click" />
right, or?
Hi,
Here is the solution. You don't need to use Session here.
Use Public Variables.
User Control Code
Parent Control Button Click code
instead of WebUserControl2, replace your User Control ID
Here is the solution. You don't need to use Session here.
Use Public Variables.
User Control Code
Public Property IsVisible() As Boolean
Get
Return m_IsVisible
End Get
Set
m_IsVisible = Value
End Set
End Property
Private m_IsVisible As Boolean
Protected Sub Page_Load(sender As Object, e As EventArgs)
End Sub
Protected Overrides Sub OnPreRender(e As EventArgs)
MyBase.OnPreRender(e)
If IsVisible Then
divTest.Attributes.Add("style", "display: normal;")
' divTest.Attributes.Add("style", "display: normal;");
Else
End If
End Sub
Parent Control Button Click code
instead of WebUserControl2, replace your User Control ID
Public Sub ButtonTest_Click(sender As Object, e As EventArgs)
WebUserControl2.IsVisible = True
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Feedback very helpful.
Do you have any Error?
Are you getting the Session value in User Control?