Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 14
  1. #1
    Utente di HTML.it
    Registrato dal
    Mar 2003
    residenza
    Prato
    Messaggi
    687

    Proprio non riesco a capire se il problema è nel mio computer o nei vari listati..

    Ciao
    Ho due codici che non vanno...
    Sono gli esercizi di fine lezione..
    Diciamo che i listati del capitolo vanno tutti ma quando arrivo sempre in fondo al capitolo alla fine trovo sempre qualcosa che non funziona..

    Giro i codici con relativo errore:

    codice:
    <%@ Page Language="VB" %>
    
    <script runat="server">
    sub ChangeNames(obj as object, e as eventargs)
    if rlSex.SelectedIndex = 0 then
    ‘femmina
    lbNames.Items(0).Text = “Sally”
    lbNames.Items(1).Text = “Sara”
    lbNames.Items(2).Text = “Hope”
    lbNames.Items(3).Text = “Kaylee”
    else
    ‘maschio
    lbNames.Items(0).Text = “John”
    lbNames.Items(1).Text = “Chris”
    lbNames.Items(2).Text = “Daniel”
    lbNames.Items(3).Text = “Walter”
    end if
    end sub
    
    sub DisplayMessage(obj as object, e as eventargs)
    lblMessage.Text = obj.SelectedItem.Text & _
    “ is a wonderful name!”
    end sub
    </script>
    
    <html><body>
    <form runat="server">
    <asp:Label id="lblMessage" runat="server" />
    
    
    
    Choose the sex of your baby:
    <asp:RadioButtonList id="rlSex" runat="server"
    OnSelectedIndexChanged=”ChangeNames”
    AutoPostBack="true">
    <asp:ListItem>Female</asp:ListItem>
    <asp:ListItem>Male</asp:ListItem>
    </asp:RadioButtonList>
    
    
    
    Possible names:
    
    <asp:ListBox id="lbNames" runat="server"
    OnSelectedIndexChanged=”DisplayMessage”
    AutoPostBack="true">
    <asp:ListItem></asp:ListItem>
    <asp:ListItem></asp:ListItem>
    <asp:ListItem></asp:ListItem>
    <asp:ListItem></asp:ListItem>
    </asp:ListBox>
    
    
    
    </form>
    </body></html>
    Errore:
    Messaggio di errore del compilatore: BC30203: È previsto un identificatore.
    Da errore nella riga 31: <asp:RadioButtonList id="rlSex" runat="server"

    codice:
    <%@ Page Language="VB" %>
    
    <script runat="server">
    sub Submit(obj as object, e as eventargs)
    if tbName.Text = “” then
    lblMessage.Text = “You forgot your name!
    ”
    end if
    if tbPhone.Text = “” then
    lblMessage.Text += “You forgot your phone!
    ”
    end if
    if tbEmail.Text = “” then
    lblMessage.Text += “You forgot your email!
    ”
    end if
    
    if lblMessage.Text = “” then
    lblMessage.Text = “Your information has been “ & _
    “submitted!”
    end if
    
    
    end sub
    </script>
    
    <html><body>
    Please enter the following information.
    
    
    
    <asp:Label id=”lblMessage” runat=”server”/>
    <form runat=”server”>
    <table cellpadding=”2” cellspacing=”2” border=”1”>
    <tr>
    <td width=”250”>Name* </td>
    <td width=”150”>
    <asp:TextBox id=”tbName” runat=”server”/>
    </td>
    </tr>
    <tr>
    <td>Address</td>
    <td>
    <asp:TextBox id=”tbAddress” runat=”server”/>
    </td>
    </tr>
    <tr>
    <td>Phone* (area code first)</td>
    <td>
    <asp:TextBox id=”tbPhone” runat=”server”/>
    </td>
    </tr>
    <tr>
    <td>Fax (area code first)</td>
    <td>
    <asp:TextBox id=”tbFax” runat=”server”/>
    </td>
    </tr>
    <tr>
    <td>Email*</td>
    <td>
    <asp:TextBox id=”tbEmail” runat=”server”/>
    </td>
    </tr>
    <tr>
    <td colspan=”2”>
    <asp:Button id=”btSubmit” runat=”server”
    Text=”Submit”
    OnClick=”Submit” />
    </td>
    </tr>
    </table>
    
    
    
    An asterisk (*) indicates a required field.
    </form>
    </body></html>
    Errore:
    Messaggio di errore del parser: L'attributo Runat deve avere solo il valore Server.
    Da errore nella riga 27: <asp:Label id=”lblMessage” runat=”server”/>

    Grazie dell'attenzione..
    Scusatemi ma devo assolutamente capire come funziona questo asp.net perchè ho diversi collaboratori che mi rallentano il lavoro e quindi stò cercando di organizzarmi per fare tutto da solo...

    Thanks
    Daniele

  2. #2
    Utente di HTML.it
    Registrato dal
    Mar 2003
    residenza
    Prato
    Messaggi
    687

    Ho risolto con il secondo listato ma il primo non riesco...

    Ciao..
    Sono riuscito a capire il problema nel secono listato che ho postato ma il primo che vedete non riesco proprio a farlo funzionare...

    Boh...

  3. #3
    Moderatore di ASP.net L'avatar di djciko
    Registrato dal
    Nov 2002
    Messaggi
    6,887
    Stai usando gli apici sbagliati in molti punti, ci vogliono i doppi apici per gli attributi dei tag.

    Es: onSelectedIndexChanged="ChangeNames" (e non onSelectedIndexChanged=”ChangeNames”).

    E' un problema di copia-incolla

  4. #4
    Utente di HTML.it
    Registrato dal
    Mar 2003
    residenza
    Prato
    Messaggi
    687

    Infatti ho capito il problema del secondo listato..

    Infatti.. Il secondo listato aveva quel problema...
    Ma il primo?

  5. #5
    Moderatore di ASP.net L'avatar di djciko
    Registrato dal
    Nov 2002
    Messaggi
    6,887
    mi sembra la stessa cosa..

    questo: ”

    non va bene ...

  6. #6
    Utente di HTML.it
    Registrato dal
    Mar 2003
    residenza
    Prato
    Messaggi
    687

    L'ho riscritto ma da errore...

    codice:
    <%@ Page Language="VB" %>
    
    <script runat="server">
    sub ChangeNames(obj as object, e as eventargs)
    if rlSex.SelectedIndex = 0 then
    'femmina
    lbNames.Items(0).Text = "Sally"
    lbNames.Items(1).Text = "Sara"
    lbNames.Items(2).Text = "Hope"
    lbNames.Items(3).Text = "Kaylee"
    else
    'maschio
    lbNames.Items(0).Text = "John"
    lbNames.Items(1).Text = "Chris"
    lbNames.Items(2).Text = "Daniel"
    lbNames.Items(3).Text = "Walter"
    end if
    end sub
    
    sub DisplayMessage(obj as object, e as eventargs)
    lblMessage.Text = obj.SelectedItem.Text & _
    " is a wonderful name!"
    end sub
    
    </script>
    <html><body>
    <form runat="server">
    <asp:Label id="lblMessage" runat="server"/>
    
    
    
    Choose the sex of your baby:
    <asp:RadioButtonList id:"rlSex" runat="server"
    OnSelectedIndexChanged="ChangeNames"
    AutoPostBack="true" >
    <asp:ListItem>Female</asp:ListItem>
    <asp:ListItem>Male</asp:ListItem>
    </asp:RadioButtonList>
    
    
    
    Possible names:
    
    <asp:ListBox id="lbNames" runat="server"
    OnSelectedIndexChanged="DisplayMessage"
    AutoPostBack="true" >
    <asp:ListItem></asp:ListItem>
    <asp:ListItem></asp:ListItem>
    <asp:ListItem></asp:ListItem>
    <asp:ListItem></asp:ListItem>
    </asp:ListBox>
    
    
    
    </form>
    </body></html>
    Messaggio di errore del parser: Il formato del tag server non è corretto.
    Riga 31: <asp:RadioButtonList id:"rlSex" runat="server"

  7. #7
    Utente di HTML.it L'avatar di pietro09
    Registrato dal
    Jan 2002
    Messaggi
    10,116
    Va bene a patto di usare le virgolette semplici, come detto dal moderatore.
    Comunque, copiato, incollato, sostituito quei caratteri con le virgolette e va

    codice:
    <%@ Page Language="VB" Strict="false" %>
    
    <script runat="server">
        Sub ChangeNames(obj As Object, e As EventArgs)
            If rlSex.SelectedIndex = 0 Then
                'femmina
                lbNames.Items(0).Text = "Sally"
                lbNames.Items(1).Text = "Sara"
                lbNames.Items(2).Text = "Hope"
                lbNames.Items(3).Text = "Kaylee"
            Else
                'maschio
                lbNames.Items(0).Text = "John"
                lbNames.Items(1).Text = "Chris"
                lbNames.Items(2).Text = "Daniel"
                lbNames.Items(3).Text = "Walter"
            End If
        End Sub
    
        Sub DisplayMessage(obj As Object, e As EventArgs)
            lblMessage.Text = obj.SelectedItem.Text & _
            " is a wonderful name!"
        End Sub
    </script>
    <html>
    <body>
        <form id="Form1" runat="server">
        <asp:Label ID="lblMessage" runat="server" />
    
    
            Choose the sex of your baby:
            <asp:RadioButtonList ID="rlSex" runat="server" OnSelectedIndexChanged="ChangeNames" AutoPostBack="true">
                <asp:ListItem>Female</asp:ListItem>
                <asp:ListItem>Male</asp:ListItem>
            </asp:RadioButtonList>
            
    
    
                Possible names:
    
                <asp:ListBox ID="lbNames" runat="server" OnSelectedIndexChanged="DisplayMessage" AutoPostBack="true">
                    <asp:ListItem></asp:ListItem>
                    <asp:ListItem></asp:ListItem>
                    <asp:ListItem></asp:ListItem>
                    <asp:ListItem></asp:ListItem>
                </asp:ListBox>
                
    
    
        </form>
    </body>
    </html>
    Pietro

  8. #8
    Utente di HTML.it
    Registrato dal
    Mar 2003
    residenza
    Prato
    Messaggi
    687

    Infatti il listato ha un errore come sospettavo..

    Ciao...
    Non riuscivo a farlo funzionare no!!
    Già la prima riga era sbagliata!!!
    <%@ Page Language="VB" Strict="false" %>

    Invece prima era così:
    <%@ Page Language="VB" %>

    Grazieeeeeeeeee ora va!!!

  9. #9
    Moderatore di ASP.net L'avatar di djciko
    Registrato dal
    Nov 2002
    Messaggi
    6,887
    Attenzione anche qui:

    codice:
    <asp:RadioButtonList id:"rlSex" runat="server"
    onSelectedIndexChanged="ChangeNames"
    AutoPostBack="true" >

    deve essere ID="rlSex", ciao

  10. #10
    Utente di HTML.it L'avatar di pietro09
    Registrato dal
    Jan 2002
    Messaggi
    10,116

    Re: Infatti il listato ha un errore come sospettavo..

    Originariamente inviato da Artgallery75
    Ciao...
    Non riuscivo a farlo funzionare no!!
    Già la prima riga era sbagliata!!!
    <%@ Page Language="VB" Strict="false" %>

    Invece prima era così:
    <%@ Page Language="VB" %>

    Grazieeeeeeeeee ora va!!!
    Ho messo quella istruzione per la fretta.
    In effetti si dovrebbe sempre mettere Strict="true", oppure nel web.config:
    <compilation strict="true" explicit="true" ****

    oppure nella pagina del codice, come prima istruzione:
    Option Strict On

    Perciò bisogna correggere dove dà errore, così:
    codice:
    Sub DisplayMessage(obj As Object, e As EventArgs)
    	'ricavo chi ha scatenato l'evento e faccio 
    	'il cast al tipo giusto
    	Dim lb As ListBox = TryCast(obj, ListBox)
    	
    	'se il cast ha esito positivo...
    	If lb IsNot Nothing Then
    		lblMessage.Text = lb.SelectedItem.Text & " is a wonderful name!"
    	End If
    End Sub
    Pietro

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.