Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    CodeBehind primi problemi

    ciao,
    è la prima ovlta che utilizzo i codebehind, sto provando del codice che funzionava perfettamente prima.

    nella mia pagina.aspx includo il codice cosi:
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="login.aspx.vb" Inherits="laspiaggetta.ViewStateInSessionVar"%>

    nel file login.aspx.vb ho questo:
    codice:
    Imports System.Data.OleDb
    Imports System.Data
    
    
    Public Class ViewStateInSessionVar
        Inherits System.Web.UI.Page
        Protected WithEvents Label1, Label2, Errore As System.Web.UI.WebControls.Label
        Protected WithEvents Button1 As System.Web.UI.WebControls.Button
        Protected WithEvents Nome, Pwd As System.Web.UI.WebControls.TextBox
    
        Sub Login(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim ObjDatabase As New laspiaggetta.TYASPNET.database()
    
            ObjDatabase.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("../mdb-database/spaiggetta-db.mdb")
    
            Dim objReader As OleDbDataReader
            objReader = ObjDatabase.SelectSQL("SELECT id FROM Admin WHERE Nome='" & ObjDatabase.Controlla_Stringa(Nome.Text) & "' AND Pwd='" & ObjDatabase.Controlla_Stringa(Pwd.Text) & "' ")
    
            If Not objReader Is Nothing Then
                Session("Admin") = "ok"
                Response.Redirect("index.aspx")
            Else
                Errore.Visible = True
                Errore.Text = "ERRORE"
            End If
            objReader.Close()
        End Sub
    
    End Class
    mi da errore qui:
    objReader.Close()

    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.


    che vuol dire?

  2. #2
    risolto l'errore stava nella stringa del db.

    cmq tenetevi pronti che sicuramente tornerò alla carica.

  3. #3
    devo fare l'upload di un file e per farlo faccio cosi:

    nel mio codicebehind ho questo:

    Protected WithEvents fotoP As Web.UI.HtmlControls.HtmlInputFile

    codice:
    sub inserisci_foto....
      Dim IO_Upload As New laspiaggetta.TYASPNET.Upload()
      Risultato_Upload = IO_Upload.Insert_Immagine(fotoP)
    .
    .
    .
    fotoP è nothing perchè?

  4. #4
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    42
    Io ho usato questo e funziona:

    Sub Upload(Source As Object, e As EventArgs)
    ___
    If Not (myFile.PostedFile Is Nothing) Then


    _ Dim intFileNameLength as Integer
    _ ______Dim strFileNamePath as String
    _ ______Dim strFileNameOnly as String___
    _ ____________
    _ ________'Logic to find the FileName (excluding the path)
    _ ________
    _____strFileNamePath = MyFile.PostedFile.FileName
    _____intFileNameLength = Instr(1,StrReverse(strFileNamePath), "\")
    _____strFileNameOnly = Mid(strFileNamePath,(Len(strFileNamePath)-intFileNameLength)+2)
    _____myFile.PostedFile.SaveAs("c:\ li tuo path \" & strFileNameOnly)
    _lblMsg.Text = "File Upload Success."
    __End If
    __
    __End Sub

    <html>
    <head>
    </head>
    <body>
    <h3>File Upload</h3>
    <form enctype="multipart/form-data" runat="server">
    File: <input id="myFile" type="file" runat="server">

    <asp:label id="lblMsg" runat="server" />

    <input type="button" value="Upload" OnServerClick="Upload" runat="server">

    </form>
    </body>
    </html>

  5. #5
    alla fine ho risolto tutto, ora va che è una favola

  6. #6
    io nella mia pagina aspx ho questo:
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="login.aspx.vb" Inherits="laspiaggetta.login" %>

    qui dentro login.aspx.vb
    c'è la classe
    Public Class login

    ricevo questo:

    The resource cannot be found.
    Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.


Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.