Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Server Side button calling page_load before calling it's own click event.

Reply
Thread Tools

Server Side button calling page_load before calling it's own click event.

 
 
Ryan Ternier
Guest
Posts: n/a
 
      07-28-2004
I have a button event:


Public Sub SwitchItem(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim btnTest As New Button
Dim astrTest As String()
btnTest = CType(sender, Button)
astrTest = btnTest.ClientID.Split("_")
strControlsToEdit = astrTest(2)
'Find out what button was pressed, then pass the flags to the
TraverseControls method.
If btnTest.Text.ToLower = "allow" Then
TraverseControls(Page, False, True)
ElseIf btnTest.Text.ToLower = "disallow" Then
TraverseControls(Page, False, False)
End If
End Sub


 
Reply With Quote
 
 
 
 
Ryan Ternier
Guest
Posts: n/a
 
      07-28-2004
Sorry, It sent without the previous being finished.
I have a function:

Public Sub SwitchItem(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim btnTest As New Button
Dim astrTest As String()
btnTest = CType(sender, Button)
astrTest = btnTest.ClientID.Split("_")
strControlsToEdit = astrTest(2)
'Find out what button was pressed, then pass the flags to the
TraverseControls method.
If btnTest.Text.ToLower = "allow" Then
TraverseControls(Page, False, True)
ElseIf btnTest.Text.ToLower = "disallow" Then
TraverseControls(Page, False, False)
End If
End Sub
___________________________
That is called By:

<asp:button cssclass="BoxType42" value="Disallow" id="btnDisAllow"
Text="Disallow" name="Disallow"
onclick="SwitchItem" runat="server" />

After the page loads up, and a user clicks this button, it will trigger the
page load event, reload the page, and not call the button's function.
However, if you click it again, it will call it. Why is this, and is there a
way around it?

The Button is bound inside a repeater, that's why I coded the onclick event.


 
Reply With Quote
 
 
 
 
Cowboy \(Gregory A. Beamer\) [MVP]
Guest
Posts: n/a
 
      07-28-2004
That is normal behavior, as Page_Load is called when the page is loaded,
prior to checking why the page is being loaded. It is the reason most coders
have:

If (Page.IsPostBack = False) Then
'run load code
Else
'run postback code
'I hate this part of the IF myself, at least as I most
'commonly see it implemented
End If



--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
"Ryan Ternier" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have a button event:
>
>
> Public Sub SwitchItem(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
> Dim btnTest As New Button
> Dim astrTest As String()
> btnTest = CType(sender, Button)
> astrTest = btnTest.ClientID.Split("_")
> strControlsToEdit = astrTest(2)
> 'Find out what button was pressed, then pass the flags to the
> TraverseControls method.
> If btnTest.Text.ToLower = "allow" Then
> TraverseControls(Page, False, True)
> ElseIf btnTest.Text.ToLower = "disallow" Then
> TraverseControls(Page, False, False)
> End If
> End Sub
>
>



 
Reply With Quote
 
Ryan Ternier
Guest
Posts: n/a
 
      07-28-2004
Yes, I have that implemented right now, but it still seems to want to reload
the page on that button click, without fireing the click event.

This is how I currently have it:

If Not IsPostBack Then
'On the first load
Page.RegisterStartupScript("MyScriptKey",
"<script>parent.frames.IFrameAdvance.resizeTo
(760,500);</script>")
....more l33t code.
Else
Dim test As String
test = "WHY ARE YOU GOING HERE J00 m34n c0mp1l3r"
End If

I really do nothing in the else, but always have a breakpoint set there
incase it hits it, so I can keep track on what
..NET is doing for performance reasons.

I'll see if I can work something out like a reload or refresh of the page
and see if that can stop the first click fiasco.

/RT


"Cowboy (Gregory A. Beamer) [MVP]" <(E-Mail Removed)> wrote
in message news:(E-Mail Removed)...
> That is normal behavior, as Page_Load is called when the page is loaded,
> prior to checking why the page is being loaded. It is the reason most

coders
> have:
>
> If (Page.IsPostBack = False) Then
> 'run load code
> Else
> 'run postback code
> 'I hate this part of the IF myself, at least as I most
> 'commonly see it implemented
> End If
>
>
>
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
>
> ************************************************
> Think Outside the Box!
> ************************************************
> "Ryan Ternier" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I have a button event:
> >
> >
> > Public Sub SwitchItem(ByVal sender As System.Object, ByVal e As
> > System.EventArgs)
> > Dim btnTest As New Button
> > Dim astrTest As String()
> > btnTest = CType(sender, Button)
> > astrTest = btnTest.ClientID.Split("_")
> > strControlsToEdit = astrTest(2)
> > 'Find out what button was pressed, then pass the flags to the
> > TraverseControls method.
> > If btnTest.Text.ToLower = "allow" Then
> > TraverseControls(Page, False, True)
> > ElseIf btnTest.Text.ToLower = "disallow" Then
> > TraverseControls(Page, False, False)
> > End If
> > End Sub
> >
> >

>
>



 
Reply With Quote
 
Cowboy \(Gregory A. Beamer\) [MVP]
Guest
Posts: n/a
 
      07-29-2004
The Page_Load will always fire, so that has to be taken out of the equation.
If the Click event is not firing, see if the "Handles XXX.Change" (or
whatever) is missing. Sometimes the events get out of sync. To resync, you
can either type this in or you can reset the event up (normally double
clicking on the control in question).

I still have not found the unique circumstances that cause this to happen,
but the VS IDE messes up event handlers from time to time.

If that is not it, post a follow up.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
"Ryan Ternier" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Yes, I have that implemented right now, but it still seems to want to

reload
> the page on that button click, without fireing the click event.
>
> This is how I currently have it:
>
> If Not IsPostBack Then
> 'On the first load
> Page.RegisterStartupScript("MyScriptKey",
> "<script>parent.frames.IFrameAdvance.resizeTo
> (760,500);</script>")
> ....more l33t code.
> Else
> Dim test As String
> test = "WHY ARE YOU GOING HERE J00 m34n c0mp1l3r"
> End If
>
> I really do nothing in the else, but always have a breakpoint set there
> incase it hits it, so I can keep track on what
> .NET is doing for performance reasons.
>
> I'll see if I can work something out like a reload or refresh of the page
> and see if that can stop the first click fiasco.
>
> /RT
>
>
> "Cowboy (Gregory A. Beamer) [MVP]" <(E-Mail Removed)>

wrote
> in message news:(E-Mail Removed)...
> > That is normal behavior, as Page_Load is called when the page is loaded,
> > prior to checking why the page is being loaded. It is the reason most

> coders
> > have:
> >
> > If (Page.IsPostBack = False) Then
> > 'run load code
> > Else
> > 'run postback code
> > 'I hate this part of the IF myself, at least as I most
> > 'commonly see it implemented
> > End If
> >
> >
> >
> > --
> > Gregory A. Beamer
> > MVP; MCP: +I, SE, SD, DBA
> >
> > ************************************************
> > Think Outside the Box!
> > ************************************************
> > "Ryan Ternier" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > I have a button event:
> > >
> > >
> > > Public Sub SwitchItem(ByVal sender As System.Object, ByVal e As
> > > System.EventArgs)
> > > Dim btnTest As New Button
> > > Dim astrTest As String()
> > > btnTest = CType(sender, Button)
> > > astrTest = btnTest.ClientID.Split("_")
> > > strControlsToEdit = astrTest(2)
> > > 'Find out what button was pressed, then pass the flags to the
> > > TraverseControls method.
> > > If btnTest.Text.ToLower = "allow" Then
> > > TraverseControls(Page, False, True)
> > > ElseIf btnTest.Text.ToLower = "disallow" Then
> > > TraverseControls(Page, False, False)
> > > End If
> > > End Sub
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
image button click event fires before click event of button Purvi T ASP .Net 0 10-19-2004 06:19 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Building Controls 1 05-28-2004 06:23 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net 2 05-25-2004 11:45 PM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Datagrid Control 0 05-25-2004 01:45 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Web Controls 0 05-25-2004 01:45 AM



Advertisments