frank_stain
03-15-2005, 10:24 AM
I am doing a login page and dropped a few web form button. When i run it in the debugger and click the button. it doesnt go into the button click sub, but instead shows a blank page. Any Ideas Much Appreciated
|
Click to See Complete Forum and Search --> : ASP.Net Buttons Wont Work frank_stain 03-15-2005, 10:24 AM I am doing a login page and dropped a few web form button. When i run it in the debugger and click the button. it doesnt go into the button click sub, but instead shows a blank page. Any Ideas Much Appreciated Cstick 03-15-2005, 05:45 PM How about posting some code to look at. PeOfEo 03-15-2005, 09:35 PM also I wrote an article about a simple asp.net login system some time ago that might be helpful to you (needs to be modified to prevent sql injection though). frank_stain 03-16-2005, 04:55 AM The Generated HTML for the code is <%@ Control Language="vb" AutoEventWireup="false" Codebehind="ctrlLogin.ascx.vb" Inherits="SellYour_House.ctrlLogin" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> <DIV style="WIDTH: 578px; POSITION: relative; HEIGHT: 288px" ms_positioning="GridLayout"> <asp:textbox id="txtUser" style="Z-INDEX: 101; LEFT: 144px; POSITION: absolute; TOP: 88px" Width="176px" runat="server"> </asp:textbox> <asp:textbox id="txtPassword" style="Z-INDEX: 102; LEFT: 144px; POSITION: absolute; TOP: 152px" Width="176px" runat="server" TextMode="Password"> </asp:textbox> <asp:button id="btnHint" style="Z-INDEX: 103; LEFT: 488px; POSITION: absolute; TOP: 32px" Width="64px" runat="server" BorderStyle="Groove" BackColor="#FF8000" BorderColor="#FF8000" ForeColor="Black" Font-Names="Arial" Font-Bold="True" Text="Hint"></asp:button> <asp:button id="btnLogon" style="Z-INDEX: 104; LEFT: 488px; POSITION: absolute; TOP: 88px" Width="64px" runat="server" BorderStyle="Groove" BackColor="#FF8000" BorderColor="#FF8000" ForeColor="Black" Font-Names="Arial" Font-Bold="True" Text="Logon"></asp:button> <asp:button id="btnClear" style="Z-INDEX: 105; LEFT: 488px; POSITION: absolute; TOP: 144px" Width="64px" runat="server" BorderStyle="Groove" BackColor="#FF8000" BorderColor="#FF8000" Font-Names="Arial" Font-Bold="True" Text="Clear"></asp:button> <asp:label id="lblHint" style="Z-INDEX: 106; LEFT: 48px; POSITION: absolute; TOP: 40px" runat="server" Font-Names="Arial" Font-Bold="True">Hint</asp:label> <asp:label id="lblHintShow" style="Z-INDEX: 107; LEFT: 144px; POSITION: absolute; TOP: 40px" Width="304px" runat="server" ForeColor="#FF8000" Font-Names="Arial"></asp:label> <asp:label id="lblPass" style="Z-INDEX: 108; LEFT: 48px; POSITION: absolute; TOP: 152px" runat="server" Font-Names="Arial" Font-Bold="True">Password:</asp:label> <asp:label id="lblUsername" style="Z-INDEX: 109; LEFT: 48px; POSITION: absolute; TOP: 88px" runat="server" Font-Names="Arial" Font-Bold="True">User Name:</asp:label> <asp:label id="lblError" style="Z-INDEX: 110; LEFT: 72px; POSITION: absolute; TOP: 240px" Width="304px" runat="server" ForeColor="#FF8000" Font-Names="Arial"></asp:label></DIV> The Code Behind will look like this Public Class ctrlLogin Inherits System.Web.UI.UserControl #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.thisConn = New System.Data.OleDb.OleDbConnection ' 'thisConn ' Me.thisConn.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _ "ocking Mode=1;Data Source=""C:\Blue Fin\SellYourHouse\SellYourHouse.mdb"";Mode=Sha" & _ "re Deny None;Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLED" & _ "B:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Prop" & _ "erties=;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:Encrypt Databas" & _ "e=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Co" & _ "mpact=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1" End Sub Protected WithEvents txtUser As System.Web.UI.WebControls.TextBox Protected WithEvents txtPassword As System.Web.UI.WebControls.TextBox Protected WithEvents btnLogon As System.Web.UI.WebControls.Button Protected WithEvents lblHint As System.Web.UI.WebControls.Label Protected WithEvents lblHintShow As System.Web.UI.WebControls.Label Protected WithEvents lblUsername As System.Web.UI.WebControls.Label Protected WithEvents lblError As System.Web.UI.WebControls.Label Protected WithEvents thisConn As System.Data.OleDb.OleDbConnection Protected WithEvents thisCommand As System.Data.OleDb.OleDbCommand Protected WithEvents btnHint As System.Web.UI.WebControls.Button Protected WithEvents btnClear As System.Web.UI.WebControls.Button Protected WithEvents lblPass As System.Web.UI.WebControls.Label 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region 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 lblHint.Visible = False lblHintShow.Visible = False End Sub Private Function ConnectToDatabase() As Boolean Try thisConn.Open() Catch ex As Exception lblError.Text = ex.Message lblError.Visible = True End Try End Function Private Function DisconnectFromDatabase() As Boolean Try thisConn.Close() Catch ex As Exception lblError.Text = ex.Message lblError.Visible = True End Try End Function Private Sub btnLogon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogon.Click '---Will Check Login Details End Sub Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click lblHintShow.Text = "" txtPassword.Text = "" txtUser.Text = "" lblHint.Text = "" End Sub End Class Cstick 03-16-2005, 05:50 PM All of your code looks good, except for the inheritance. I'm almost certain that it is the problem. Try this and let us know how it does. You have: Inherits System.Web.UI.UserControl It should be: Inherits System.Web.UI.Page dtch 03-17-2005, 09:18 AM Did you change the name of the button, cut it, or move it...? Try deleting the button, add a new button on the user control. Double click the button to go to the code behind page and create the new button_click event. Delete the old event. (Don't forget to copy your code in there first.) :-) Add the user control a web form and test it. It should work. Sometimes renaming a button, or something else disconnects it from its event handler. Good Luck! frank_stain 03-22-2005, 05:06 AM CStick when i did what you suggested i got the following error 'SellYour_House.ctrlLogin' is not a valid base class because it does not extend class 'System.Web.UI.UserControl'. dtch i put in a new button but no success. All the buttons dont work so there must be some other reason they all just load an empty page the address at the top still says the original .aspx address frank_stain 03-22-2005, 05:49 AM just stepped through code. when the button is pressed it goes to the page initialise that calls the user control and not the button press event. Anyone know why Its really bugging me Cstick 03-22-2005, 06:00 PM Try this. In your html, add the commandname attribute with method like below. <asp:button commandname="btnLogon_Click" id="btnLogon" style="Z-INDEX: 104; LEFT: 488px; POSITION: absolute; TOP: 88px" Width="64px" runat="server" BorderStyle="Groove" BackColor="#FF8000" BorderColor="#FF8000" ForeColor="Black" Font-Names="Arial" Font-Bold="True" Text="Logon"></asp:button> In your codebehind, change you click method to this. Make it public and remove handling. Public Sub btnLogon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) '---Will Check Login Details End Sub Let us know if that helped. frank_stain 03-23-2005, 03:10 AM i actually got it workin. i moved a piece of my code into the page_load which was peviously elesewhere and it fixed the problem Cheers for all your help webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |