0
votes

I'm new in ASPX and VB.net so i'm trying to implement simple onClick method from my aspx page to open a new one but i'm getting the following error:

Button is not a member of asp.net.

Here is my simple html page with bootstrap:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="login.aspx.vb" Inherits="gabServizi.login" %>

<!DOCTYPE html>

<html>
<head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
    <link rel="icon" href="/img/favicon.ico">
    <title>Gab Servizi: Login</title>
    <link href="Content/bootstrap.min.css" rel="stylesheet" />
    <link href="style/login.css" type="text/css" rel="stylesheet" />

</head>

  <body class="text-center">
    <form class="form-signin fade-in">
      <img class="mb-2 " src="/img/gabservizi.png" alt="" width="160" height="160">

      <h1 class="h3 mb-3 font-weight-normal" translate="yes">Accedi a Gab Servizi!</h1>
      <label for="inputEmail" class="sr-only">Email</label> 
      <input type="email" id="inputEmail" class="form-control" placeholder="Email..." required autofocus>

      <label for="inputPassword" class="sr-only">Password</label>
      <input type="password" id="inputPassword" class="form-control" placeholder="Password..." required>

       <div class="custom-control custom-checkbox mb-3">

           <input type="checkbox" class="custom-control-input" id="ricordaCheck">
           <label class="custom-control-label" for="ricordaCheck">Ricordami</label>

       </div>

        <asp:Button class="btn btn-lg btn-primary btn-block" ID="Button1" runat="server" Text="Accedi" onClick="Button1_Click" />

      <p class="text-muted mt-2 mb-3">Non hai un account? <a href="register.aspx" class="text-primary"> Registrati!</a></p>

      <p class="mt-4 mb-3 text-muted">GAB Tamagnini © 2014 Via Beniamino Disraeli, 17, 42124 Reggio Emilia</p>
    </form>
  </body>

</html>

And here is the vb part:

Public Class login
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Response.Redirect("index.aspx")
    End Sub
End Class
1
You don't need to Handles the event if you already set it in the onClick - the_lotus
This isn't a good idea. If you have a button that causes a postback to the webserver which then performs a redirect, then you've wasted unnecessary server resources and your client is going to think your site is slow. Don't have a button that just does a redirect. It's a bad user experience. If you want, you can create a hyperlink that appears to be a button. Since you're using Bootstrap, that'd be something like <a href="index.aspx" class="btn">Accedi</a>. - mason

1 Answers

1
votes

Hi try this one by using a server-side method

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

       Server.Transfer("index.aspx", True)

End Sub