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

    probelma con passaggio variabili da pagina asp a pagina aspnet

    Buon giorno a tutti.
    Non molto esperto già del linguaggio che uso comunemente (asp) ho la necessità di interagire con una pagina aspx, ma proprio non capisco l'errore.
    Dunque da una pagina asp ho il seguente link
    <a href="../scripts/ad_images.aspx?ad_id=<%=ad_id%>&picnumber=<%=picnu mber%>">
    la pagina ricevente, aspx, appunto mi restituisce sempre errore. Non capisco come accidenti devo fare per recuperare questi due numeri.
    Ho provato prima con
    if (Request.QueryString["ad_id"] != null) Then Ad_Id = Convert.ToInt32(Request.QueryString["ad_id"]) end if ma non funziona.
    Poi con
    Dim Ad_id as String
    Ad_Id = Convert.ToInt32(Request.QueryString["Ad_Id"]).

    Questi sono solo due dei numerosi tentativi che ho fatto ma di c# non conosco nulla.
    Per favore qualcuno mi potrebbe dare una mano? Grazie
    ODIO fare il Debug......Grrrrrr!

  2. #2
    Utente di HTML.it L'avatar di pietro09
    Registrato dal
    Jan 2002
    Messaggi
    10,116
    pagina asp
    codice:
    <%
    dim ad_id, picnumber
    
    ad_id = 99
    picnumber = 77
    
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
        vai a a.aspx
    </body>
    </html>
    pagina aspx
    codice:
    <%@ Page Language="VB" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim ad_id As String = Me.Request.QueryString("ad_id")
            Dim picnumber As String = Me.Request.QueryString("picnumber")
            
            If ad_id IsNot Nothing Then
                Me.Label1.Text = "ad_id = " & ad_id
            End If
    
            If picnumber IsNot Nothing Then
                Me.Label2.Text = "picnumber = " & picnumber
            End If
    
        End Sub
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Label ID="Label1" runat="server" Text="" EnableViewState="false"></asp:Label>
            
    
            <asp:Label ID="Label2" runat="server" Text="" EnableViewState="false"></asp:Label>
        </div>
        </form>
    </body>
    </html>

    Il problema è che hai inventato un linguaggio che non c'è.
    Così come in asp puoi utilizzare il vbscript o il jscsript, in asp.net puoi utilizzare il basic, il c#, il j# e altro.
    Pietro

  3. #3
    grazie pietro. sei stato molto gentile. funziona perfettamente.
    ODIO fare il Debug......Grrrrrr!

  4. #4
    pietro scusa se disturbo ancora ma ho uno strano problema
    le due variabili vengono recuperate e stampate a video ma non riesco ad usarle in altro modo. cioè quei due numeri devono far parte del nome di un file che viene creato da questa pagina aspx, appunto. Posto tutta la pagina così ci capisci/capite meglio. (è' un esempio trovato sul web che serve per fare l'upload ed il resize delle immagini.) Ho evidenziato in rosso le due righe dove avviene la concatenazione di costanti e variabili ma non vengono assunti i due valori in questione. L'output nella cartella delle immagini dovrebbe essere "Ad_Id+numero annuncio+numero foto.ext", per la foto e "Ad_Id+numero annuncio+numero foto+_thumb.ext", per la miniatura creata.

    <%@ Page Trace="False" Language="vb" aspcompat="false" debug="true" validateRequest="false"%>
    <%@ Import Namespace=System.Drawing %>
    <%@ Import Namespace=System.Drawing.Imaging %>
    <%@ Import Namespace=System %>
    <%@ Import Namespace=System.Web %>
    <SCRIPT LANGUAGE="VBScript" runat="server">

    const Lx = 200
    const Ly = 240
    const upload_dir = "/ad_images/"
    const upload_original = "Ad_"
    const upload_thumb = "_thumb"
    const upload_max_size = 1500
    dim fileExt
    dim newWidth, newHeight as integer
    dim l2
    dim fileFld as HTTPPostedFile
    Dim originalimg As System.Drawing.Image
    dim msg
    dim upload_ok as boolean
    dim ad_id
    dim picnumber
    </script>
    <script language="vbscript" runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim ad_id As String = Me.Request.QueryString("ad_id")
    Dim picnumber As String = Me.Request.QueryString("picnumber")

    If ad_id IsNot Nothing Then
    Me.Label1.Text = "ad_id = " & ad_id
    End If

    If picnumber IsNot Nothing Then
    Me.Label2.Text = "picnumber = " & picnumber
    End If

    End Sub
    </script>
    <%

    randomize()
    upload_ok = false
    if lcase(Request.ServerVariables("REQUEST_METHOD"))=" post" then
    fileFld = request.files(0) ' get the first file uploaded from the form (note:- you can use this to itterate through more than one image)
    if fileFld.ContentLength > upload_max_size * 1024 then
    msg = "Attenzione, l'immagine deve essere max " & upload_max_size & "Mb"
    else
    try
    originalImg = System.Drawing.Image.FromStream(fileFld.InputStrea m)
    If (originalImg.Width/Lx) > (originalImg.Width/Ly) Then
    L2 = originalImg.Width
    newWidth = Lx
    newHeight = originalImg.Height * (Lx / L2)
    if newHeight > Ly then
    newWidth = newWidth * (Ly / newHeight)
    newHeight = Ly
    end if
    Else
    L2 = originalImg.Height
    newHeight = Ly
    newWidth = originalImg.Width * (Ly / L2)
    if newWidth > Lx then
    newHeight = newHeight * (Lx / newWidth)
    newWidth = Lx
    end if
    End If

    Dim thumb As New Bitmap(newWidth, newHeight)

    Dim gr_dest As Graphics = Graphics.FromImage(thumb)

    dim sb = new SolidBrush(System.Drawing.Color.White)
    gr_dest.FillRectangle(sb, 0, 0, thumb.Width, thumb.Height)

    gr_dest.DrawImage(originalImg, 0, 0, thumb.Width, thumb.Height)

    try
    fileExt = System.IO.Path.GetExtension(fileFld.FileName).ToLo wer()
    originalImg.save(Server.MapPath(upload_dir & upload_original & ad_id & "_" & picnumber & fileExt), originalImg.rawformat)
    thumb.save(Server.MapPath(upload_dir & upload_original & ad_id & "_" & picnumber & upload_thumb & fileExt), originalImg.rawformat)
    msg = "Uploaded " & fileFld.FileName & " to " & Server.MapPath(upload_dir & upload_original & fileExt)
    upload_ok = true
    catch
    msg = "Sorry, there was a problem saving the image."
    end try
    ' Housekeeping for the generated thumbnail
    if not thumb is nothing then
    thumb.Dispose()
    thumb = nothing
    end if
    catch
    msg = "Si è verificato un Errore. L'immagine non è stata elaborata."
    end try
    end if

    ' House Keeping !
    if not originalImg is nothing then
    originalImg.Dispose()
    originalImg = nothing
    end if

    end if
    %>
    <html>
    <head>
    <title>ASP.NET File Upload and Resize Sample</title>
    <META NAME="Description" CONTENT="ASP.NET File Upload and Resize Sample (Hybrid VB.NET)">
    <META NAME="Keywords" CONTENT="ASP.NET, ASP, NET, VB, VBScript, Image, Upload, Resize, Thumbnail, Constrain, Filesize, File, Size, Free">
    <META NAME="Copyright" CONTENT="Rufan-Redi Pty Ltd 2005">
    <META NAME="Author" CONTENT="System developed by Jeremy at http://www.Rufan-Redi.com">
    </head>
    <body>



    Hybrid ASP.NET File Upload and Resize Sample (VB.NET)

    Upload and resize a GIP/JPG/PNG images, ensuring filesizes are optimum.</p>

    <form id="form1" enctype="multipart/form-data" method="post" runat="server">
    <table>
    <tr><td>Select the file to upload:</td><td><input type="file" name="upload_file"></td></tr>
    <tr><td colspan=2>Max upload size <%=upload_max_size%>Kb, gif/jpg/png only</td></tr>
    <tr><td colspan=2><input type="submit" value="Upload"></td></tr>
    <tr><td><asp:Label ID="Label1" runat="server" Text="" EnableViewState="false"></asp:Label>


    <asp:Label ID="Label2" runat="server" Text="" EnableViewState="false"></asp:Label>
    </td></tr>
    </table>
    </form>

    <%
    if upload_ok then
    %>
    <table>
    <tr>
    <td valign=top>[img]<%=upload_dir & upload_original & ad_id & [/img]"></td>
    <td valign=top>[img]<%=upload_dir & upload_original & ad_id & [/img]"></td>
    </tr>
    </table>
    <%
    else
    response.write(msg)
    end if
    %>
    </body>
    </html>
    ODIO fare il Debug......Grrrrrr!

  5. #5
    Utente di HTML.it L'avatar di pietro09
    Registrato dal
    Jan 2002
    Messaggi
    10,116
    a me sembra che vada :master:
    codice:
    <%@ Page Trace="False" Language="vb" AspCompat="false" Debug="true" ValidateRequest="false" Strict="false" %>
    
    <%@ Import Namespace="System.Drawing" %>
    <%@ Import Namespace="System.Drawing.Imaging" %>
    <%@ Import Namespace="System" %>
    <%@ Import Namespace="System.Web" %>
    
    <script language="VBScript" runat="server">
    
        Const Lx = 200
        Const Ly = 240
        Const upload_dir = "/tmp/"
        Const upload_original = "Ad_"
        Const upload_thumb = "_thumb"
        Const upload_max_size = 1500
        Dim fileExt
        Dim newWidth, newHeight As Integer
        Dim l2
        Dim fileFld As HttpPostedFile
        Dim originalimg As System.Drawing.Image
        Dim msg
        Dim upload_ok As Boolean
        Dim ad_id
        Dim picnumber
    </script>
    
    
    <%
        ad_id = Request.QueryString("ad_id")
        picnumber = Request.QueryString("picnumber")
        
        Randomize()
        upload_ok = False
        If LCase(Request.ServerVariables("REQUEST_METHOD")) = "post" Then
            fileFld = Request.Files(0) ' get the first file uploaded from the form (note:- you can use this to itterate through more than one image)
            If fileFld.ContentLength > upload_max_size * 1024 Then
                msg = "Attenzione, l'immagine deve essere max " & upload_max_size & "Mb"
            Else
                Try
                    originalimg = System.Drawing.Image.FromStream(fileFld.InputStream)
                    If (originalimg.Width / Lx) > (originalimg.Width / Ly) Then
                        l2 = originalimg.Width
                        newWidth = Lx
                        newHeight = originalimg.Height * (Lx / l2)
                        If newHeight > Ly Then
                            newWidth = newWidth * (Ly / newHeight)
                            newHeight = Ly
                        End If
                    Else
                        l2 = originalimg.Height
                        newHeight = Ly
                        newWidth = originalimg.Width * (Ly / l2)
                        If newWidth > Lx Then
                            newHeight = newHeight * (Lx / newWidth)
                            newWidth = Lx
                        End If
                    End If
    
                    Dim thumb As New Bitmap(newWidth, newHeight)
    
                    Dim gr_dest As Graphics = Graphics.FromImage(thumb)
    
                    Dim sb = New SolidBrush(System.Drawing.Color.White)
                    gr_dest.FillRectangle(sb, 0, 0, thumb.Width, thumb.Height)
    
                    gr_dest.DrawImage(originalimg, 0, 0, thumb.Width, thumb.Height)
    
                    Try
                        fileExt = System.IO.Path.GetExtension(fileFld.FileName).ToLower()
                        originalimg.Save(Server.MapPath(upload_dir & upload_original & ad_id & "_" & picnumber & fileExt), originalimg.RawFormat)
                        thumb.Save(Server.MapPath(upload_dir & upload_original & ad_id & "_" & picnumber & upload_thumb & fileExt), originalimg.RawFormat)
                        msg = "Uploaded " & fileFld.FileName & " to " & Server.MapPath(upload_dir & upload_original & fileExt)
                        upload_ok = True
                    Catch
                        msg = "Sorry, there was a problem saving the image."
                    End Try
                    ' Housekeeping for the generated thumbnail
                    If Not thumb Is Nothing Then
                        thumb.Dispose()
                        thumb = Nothing
                    End If
                Catch
                    msg = "Si è verificato un Errore. L'immagine non è stata elaborata."
                End Try
            End If
    
            ' House Keeping !
            If Not originalimg Is Nothing Then
                originalimg.Dispose()
                originalimg = Nothing
            End If
    
        End If
    %>
    <html>
    <head>
        <title>ASP.NET File Upload and Resize Sample</title>
        <meta name="Description" content="ASP.NET File Upload and Resize Sample (Hybrid VB.NET)">
        <meta name="Keywords" content="ASP.NET, ASP, NET, VB, VBScript, Image, Upload, Resize, Thumbnail, Constrain, Filesize, File, Size, Free">
        <meta name="Copyright" content="Rufan-Redi Pty Ltd 2005">
        <meta name="Author" content="System developed by Jeremy at http://www.Rufan-Redi.com">
    </head>
    <body>
        
    
    
            Hybrid ASP.NET File Upload and Resize Sample (VB.NET)
            
    
            Upload and resize a GIP/JPG/PNG images, ensuring filesizes are optimum.</p>
        <form id="form1" enctype="multipart/form-data" method="post" runat="server">
        <table>
            <tr>
                <td>
                    Select the file to upload:
                </td>
                <td>
                    <input type="file" name="upload_file">
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    Max upload size
                    <%=upload_max_size%>Kb, gif/jpg/png only
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="submit" value="Upload">
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label1" runat="server" Text="" EnableViewState="false"></asp:Label>
                    
    
                    <asp:Label ID="Label2" runat="server" Text="" EnableViewState="false"></asp:Label>
                </td>
            </tr>
        </table>
        </form>
        <%
            If upload_ok Then
        %>
        <table>
            <tr>
                <td valign="top">
                    [img]<%=upload_dir & upload_original & ad_id & [/img]">
                </td>
                <td valign="top">
                    [img]<%=upload_dir & upload_original & ad_id & [/img]">
                </td>
            </tr>
        </table>
        <%
        Else
            Response.Write(msg)
        End If
        %>
    </body>
    </html>
    Pietro

  6. #6
    perfetto..grazie ancora.
    ODIO fare il Debug......Grrrrrr!

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.