CLR: .Net / Mono / Boo / Otros CLR > ASP .NET

 Ejecutar Formulario Asp.net

<< < (2/3) > >>

lulial:
Hola, tengo un botón llamado Button1 el código del botón está dentro de la clase del formulario, creo que el código está bien lo muestro por si acaso.
Pongo como me has dicho el punto de ruptura en "Private Sub Button1_Click" y abro la página pulso en el botón y nada no me va al código.

Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents Label3 As System.Web.UI.WebControls.Label
    Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
    Protected WithEvents Button2 As System.Web.UI.WebControls.Button
    Protected WithEvents Button3 As System.Web.UI.WebControls.Button
    Protected WithEvents SqlCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection

#Region " Código generado por el Diseñador de Web Forms "

    'El Diseñador de Web Forms requiere esta llamada.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection()
        Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection()
        Me.SqlCommand1 = New System.Data.SqlClient.SqlCommand()
        '
        'SqlConnection1
        '
        Me.SqlConnection1.ConnectionString = "data source=MMG-E8BFAD4E0D5;initial catalog=ClientesWindows;integrated security=S" & _
        "SPI;persist security info=False;workstation id=MMG-E8BFAD4E0D5;packet size=4096"
        '
        'OleDbConnection1
        '
        Me.OleDbConnection1.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial " & _
        "Catalog=ClientesWindows;Data Source=MMG-E8BFAD4E0D5;" & Microsoft.VisualBasic.ChrW(0)
        '
        'SqlCommand1
        '
        Me.SqlCommand1.Connection = Me.SqlConnection1

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: el Diseñador de Web Forms requiere esta llamada de método
        'No lo modifique con el editor de código.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Introducir aquí el código de usuario para inicializar la página
        If Not Page.IsPostBack = True Then
            Panel1.Visible = False
            Button2.Visible = False
            Button3.Visible = False
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim intCodCliente As Integer
        Dim strNomCliente As String
        Dim miExcepcion3 As Exception

        If TextBox1.Text = "" Then
            Label3.Text = "hay que introducir un número de cliente"
            Exit Sub
        End If
        Try
            intCodCliente = CInt(TextBox1.Text)
        Catch miExcepcion As Exception
            Label3.Text = "Hay que introducir un número de cliente"
            Exit Sub
        End Try

        Try
            SqlConnection1.Open()
        Catch miExcepcion1 As Exception
            Label3.Text = "no se puede abrir la conexion"
            Exit Sub
        End Try


        Try
            SqlCommand1.CommandText = "select NombreCliente from clientes where idCliente = " & intCodCliente & ""
            strNomCliente = SqlCommand1.ExecuteScalar
            Session("NombreCliente") = strNomCliente

            If strNomCliente = "" Then
                Throw miExcepcion3
            End If
            Label3.Text = "usuario : " & strNomCliente & ""
            Panel1.Visible = True
            Button2.Visible = True
            Button3.Visible = True
            Session("idCliente") = intCodCliente


        Catch miExcepcion3
            Label3.Text = "Este cliente no existe"
            Panel1.Visible = False
            Button2.Visible = False
            Button3.Visible = False
            Exit Sub
        Finally
            SqlConnection1.Close()

        End Try


    End Sub
End Class

gracias

Javier Santamaria:
Hola de nuevo, debe de ejecutar ese codigo. Vamos a ver prueba a hacer esto:

En el codigo:


--- Código: Text --- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim intCodCliente As IntegerDim strNomCliente As StringDim miExcepcion3 As Exception If TextBox1.Text = &#34;&#34; Then [COLOR=red](pon el breakpoint en esta linea)[/COLOR]Label3.Text = &#34;hay que introducir un número de cliente&#34;Exit SubEnd IfTryintCodCliente = CInt(TextBox1.Text)Catch miExcepcion As ExceptionLabel3.Text = &#34;Hay que introducir un número de cliente&#34;Exit SubEnd Try TrySqlConnection1.Open()Catch miExcepcion1 As ExceptionLabel3.Text = &#34;no se puede abrir la conexion&#34;Exit SubEnd Try  TrySqlCommand1.CommandText = &#34;select NombreCliente from clientes where idCliente = &#34; & intCodCliente & &#34;&#34;strNomCliente = SqlCommand1.ExecuteScalarSession(&#34;NombreCliente&#34;) = strNomCliente If strNomCliente = &#34;&#34; ThenThrow miExcepcion3End IfLabel3.Text = &#34;usuario : &#34; & strNomCliente & &#34;&#34;Panel1.Visible = TrueButton2.Visible = TrueButton3.Visible = TrueSession(&#34;idCliente&#34;) = intCodCliente  Catch miExcepcion3Label3.Text = &#34;Este cliente no existe&#34;Panel1.Visible = FalseButton2.Visible = FalseButton3.Visible = FalseExit SubFinallySqlConnection1.Close() End Try  End Sub 
Cuando hagas esto presiona "F5" (solo F5, no Ctrl + F5)
Cuando presiones el boton se deberia para en el breakpoint y señalizarte la instruccion que se va a ejecutar en amarillo. Pulsa F10 para avanzar una instruccion. Conforme avances las instrucciones comprueba que los valores de las variables sean los correctos. Para hacer esa comprobacion en la parte inferior tienes una ventanita con varias pestañas, vete a la pestaña de local y ahi te salen las variables y sus valores.

Ya nos cuentas.

Saludos

lulial:
Nada, he puesto el breakpoint en la siguiente linea:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

pulso Ctrl+F5 se me ejecuta la aplicación pulso al botón Button1 y nada no hace nada, no va al punto del código así que no lo puedo comprobar.

Javier Santamaria:
Hola,

No me has entendido o no me explico bien, el breakpoint ponlo en

--- Código: Text ---If TextBox1.Text = &#34;&#34; Then Y luego pulsa solo F5,  NO "Ctrl+F5"

A ver si en esta si nos funciona.

lulial:
nada sigue sin entrar en el breakpoint, no me aparece ninguna linea en amarillo.

Navegación

[0] Índice de Mensajes

[#] Página Siguiente

[*] Página Anterior

Ir a la versión completa