[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Brian Peasey

1/20/2003 11:19:00 PM

Hi,

I have a button that when clicked sets a session variable to the button's
ID. In my Page Load event I am trying to findout what button was clicked by
checking the session variable. However, when the button is clicked the Page
Load event happens before my onclick handler, so the session variable =
nothing. Basically when a button is clicked the code decides which user
control to load. Any techniques or suggestion to avoid the clicking twice
issue?

Code below:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If IsPostBack = True Then
If Session("button_name") = "btnHome" Then
Dim c1 As UserControl = LoadControl("generic.ascx")
Panel1.Controls.Add(c1)
btnHome.BorderStyle = BorderStyle.Inset
btnReports.BorderStyle = BorderStyle.NotSet
ElseIf Session("button_name") = "btnReports" Then
Dim c2 As UserControl = LoadControl("criteria.ascx")
Panel1.Controls.Add(c2)
btnReports.BorderStyle = BorderStyle.Inset
btnHome.BorderStyle = BorderStyle.NotSet
End If
End If
End Sub

Protected Sub btnReports_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnReports.Click
Session("button_name") = "btnReports"
End Sub

Best Regards,
Brian


3 Answers

christopher pragash

1/21/2003 12:16:00 AM

0

Brian,

I faced a similar problem, but with a slightly different architecture. I had
a page with two controls, a Navigation Control and a Body control, and all
the page did was to load up the navigation control first and then the body
control. I wanted to manipulate the Navigation control based on the actions
in the Body Control, and found that the (aspx) Page_load (not ascx) event
was fired before the actual actions inside the body controls submit button
event were performed. During page_load, the page actually posts back and
loads the navigation control and the body control...and then fires the
submit event of the body control. I did a workaround by passing a reference
of the navigation control from the page to the body control and then
manipulating it. I could not understand the event firing chronology!

In your case i guess you could put the dynamic loading condition in the
button click event and consider changing the IsPostBack to false. This way
the page would not keep loading the control at every postback. I would also
check the PostBackProperty of the button...and if it is true, turn it to
false

I'm not sure if this helps...

Chris

"Brian Peasey" <bpeasey@doncarsys.com> wrote in message
news:#fDYtGNwCHA.2124@TK2MSFTNGP11...
> Hi,
>
> I have a button that when clicked sets a session variable to the button's
> ID. In my Page Load event I am trying to findout what button was clicked
by
> checking the session variable. However, when the button is clicked the
Page
> Load event happens before my onclick handler, so the session variable =
> nothing. Basically when a button is clicked the code decides which user
> control to load. Any techniques or suggestion to avoid the clicking twice
> issue?
>
> Code below:
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> If IsPostBack = True Then
> If Session("button_name") = "btnHome" Then
> Dim c1 As UserControl = LoadControl("generic.ascx")
> Panel1.Controls.Add(c1)
> btnHome.BorderStyle = BorderStyle.Inset
> btnReports.BorderStyle = BorderStyle.NotSet
> ElseIf Session("button_name") = "btnReports" Then
> Dim c2 As UserControl = LoadControl("criteria.ascx")
> Panel1.Controls.Add(c2)
> btnReports.BorderStyle = BorderStyle.Inset
> btnHome.BorderStyle = BorderStyle.NotSet
> End If
> End If
> End Sub
>
> Protected Sub btnReports_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnReports.Click
> Session("button_name") = "btnReports"
> End Sub
>
> Best Regards,
> Brian
>
>


Gregor Streng

1/21/2003 1:15:00 PM

0

Hi Brian,

There is no way this is going to work for you, because the Page_Load Event
gets served before
any PostbackEvent.

1) Page_Load
2) Button Click

What means for you that validating the Session variable in your Page_Load
event won't work.
You need to relocate this into your click event.


Hope this helps,
Gregor Streng


"Brian Peasey" <bpeasey@doncarsys.com> wrote in message
news:#fDYtGNwCHA.2124@TK2MSFTNGP11...
> Hi,
>
> I have a button that when clicked sets a session variable to the button's
> ID. In my Page Load event I am trying to findout what button was clicked
by
> checking the session variable. However, when the button is clicked the
Page
> Load event happens before my onclick handler, so the session variable =
> nothing. Basically when a button is clicked the code decides which user
> control to load. Any techniques or suggestion to avoid the clicking twice
> issue?
>
> Code below:
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> If IsPostBack = True Then
> If Session("button_name") = "btnHome" Then
> Dim c1 As UserControl = LoadControl("generic.ascx")
> Panel1.Controls.Add(c1)
> btnHome.BorderStyle = BorderStyle.Inset
> btnReports.BorderStyle = BorderStyle.NotSet
> ElseIf Session("button_name") = "btnReports" Then
> Dim c2 As UserControl = LoadControl("criteria.ascx")
> Panel1.Controls.Add(c2)
> btnReports.BorderStyle = BorderStyle.Inset
> btnHome.BorderStyle = BorderStyle.NotSet
> End If
> End If
> End Sub
>
> Protected Sub btnReports_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnReports.Click
> Session("button_name") = "btnReports"
> End Sub
>
> Best Regards,
> Brian
>
>


(Aaron)

1/21/2003 4:11:00 PM

0

Brana,

Have you tried a VB6 Toggle Button?

Aaron
"Gregor Streng" <gregorstreng@jamieplc.com> wrote in message
news:#iO7yaUwCHA.2604@TK2MSFTNGP12...
> Hi Brian,
>
> There is no way this is going to work for you, because the Page_Load Event
> gets served before
> any PostbackEvent.
>
> 1) Page_Load
> 2) Button Click
>
> What means for you that validating the Session variable in your Page_Load
> event won't work.
> You need to relocate this into your click event.
>
>
> Hope this helps,
> Gregor Streng
>
>
> "Brian Peasey" <bpeasey@doncarsys.com> wrote in message
> news:#fDYtGNwCHA.2124@TK2MSFTNGP11...
> > Hi,
> >
> > I have a button that when clicked sets a session variable to the
button's
> > ID. In my Page Load event I am trying to findout what button was clicked
> by
> > checking the session variable. However, when the button is clicked the
> Page
> > Load event happens before my onclick handler, so the session variable =
> > nothing. Basically when a button is clicked the code decides which user
> > control to load. Any techniques or suggestion to avoid the clicking
twice
> > issue?
> >
> > Code below:
> >
> > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles MyBase.Load
> > 'Put user code to initialize the page here
> > If IsPostBack = True Then
> > If Session("button_name") = "btnHome" Then
> > Dim c1 As UserControl = LoadControl("generic.ascx")
> > Panel1.Controls.Add(c1)
> > btnHome.BorderStyle = BorderStyle.Inset
> > btnReports.BorderStyle = BorderStyle.NotSet
> > ElseIf Session("button_name") = "btnReports" Then
> > Dim c2 As UserControl = LoadControl("criteria.ascx")
> > Panel1.Controls.Add(c2)
> > btnReports.BorderStyle = BorderStyle.Inset
> > btnHome.BorderStyle = BorderStyle.NotSet
> > End If
> > End If
> > End Sub
> >
> > Protected Sub btnReports_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles btnReports.Click
> > Session("button_name") = "btnReports"
> > End Sub
> >
> > Best Regards,
> > Brian
> >
> >
>
>