473,404 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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

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
Nov 18 '05 #1
4 3370
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.
Nov 18 '05 #2
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" <rt******@icompasstech.com.spamproof> wrote in message
news:ea*************@TK2MSFTNGP11.phx.gbl...
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

Nov 18 '05 #3
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]" <No************@comcast.netNoSpamM> wrote
in message news:u1*************@tk2msftngp13.phx.gbl...
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" <rt******@icompasstech.com.spamproof> wrote in message
news:ea*************@TK2MSFTNGP11.phx.gbl...
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


Nov 18 '05 #4
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" <rt******@icompasstech.com.spamproof> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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]" <No************@comcast.netNoSpamM> wrote in message news:u1*************@tk2msftngp13.phx.gbl...
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" <rt******@icompasstech.com.spamproof> wrote in message
news:ea*************@TK2MSFTNGP11.phx.gbl...
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



Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: HarveyB | last post by:
I would like to generate non-modal popup windows from ASP.Net code-behind. I have tried using Client Side scripting like "function Test(){ window.open('test.htm',_blank,...
3
by: Reetu | last post by:
Hi All, I have an html button on .aspx page. <INPUT class="sbttn" id="btnComplete0" onclick="onComplete ()" type="button" value="Mark Completed" name="btnComplete0"> When the user clicks...
3
by: Karim | last post by:
I have a button that opens a new Window using client side Javascript. The button also has server side script (.._click) that saves some session variables to be used in the new Window. The...
6
by: Michael Johnson Jr. | last post by:
I am trying to handle a button click event, which updates a web control table with data. The button is dynamically created in the table itself. When I call updateTable() in the Page_Load the new...
3
by: interuser | last post by:
Hi How can I prevent an event (eg button click) from happening from within page_load? The reason is that I want to make my existing application work for netscape, for which there are no client...
9
by: AFN | last post by:
I was just dropped into someone else's code (isn't that always so fun?). I can't figure out why a custom validation control's server event function is executing. There is nothing (that I see)...
4
by: Mohammed AlQuraishi | last post by:
Hi, I'm having trouble with synchronizing the order of server-side events, and I was hoping someone here can shed some light on what's happening. In a simplified version, I click on a button...
1
by: Perry van Kuppeveld | last post by:
Hi, I would like to submit a form through scripting, and still retrieve the click event on the server. See code below to test some stuff. Create a C# webapplication and replace the WebForm1...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.