Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button.Click

Status
Not open for further replies.

NaiDanac

Programmer
Mar 25, 2004
96
US
I've got a strange problem. I have server controls in my .aspx page, but they don't seem to fire up.

For example, I have two controls, button1 and button2. When I click on button1, button2.visible = false.

If I put that code in the button1_click procedure it doesn't do much:
Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button2.Visible = False
    End Sub

However, when I put the Button2.Visible = False in the page load sub procedure, it does get executed (when the page loads)
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
.....
        Button2.Visible = False
....

Any reason why?
 
Nail: The following code worked just fine:

Code:
<%@ Page Language="VB"%>
<%@Import Namespace = "Microsoft.VisualBasic"%>
<script runat="server">
Sub btn1_Click(s As Object, e As EventArgs)
  btn2.visible="false"
End Sub
</script>
<html>
<head>
<title>Test button</title>
</head>
<body>
<form id="Form1" runat="server">
  <asp:button id="btn1" runat="server" text="btn1" OnClick="btn1_Click"/>
  <asp:button id="btn2" runat="server" text="btn2"/>
</form>
</body>
</html>

..so on first glance there doesn't seem to be a thing wrong with what you have; removing "Private" changes nothing; as expected -- hard to say what it could be -- paste the above in Notepad and see if it behaves.
Could it be related to the Page Load --> btnClick --> preRender ordering??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top