119 messaggi dal 03 giugno 2003
Ti ringrazio tantissimo degli esempi. Io cmq ero già riuscito a mettere in piedi un js con che mi carica le dropdwon list a cascata (scelgo la provincia e mi carica i comuni della provincia) e funziona...
La mia pagina server è pressochè simile alla tua che torna un xml e che uso nel mio js per caricare le tendine combo.

Il problema resta quando ho degli eventi post back nella pagina. Tipo il bottone di salva.... Da un errore che devo disabilitare il EnableEventValidation ma funziona .... ma poi ogni postback perdo i valori selezionati nella combo caricata con ajax...

Spero di essere stato chiaro .... se potete darmi una dritta...
3.165 messaggi dal 06 settembre 2002
Contributi | Blog
Ciao,

é normale che ti perda i dati nelle combo, perchè asp.net ricostruisce tutto dal viewstate e quello non può essere modificato da js. per ovviare ad ogni postback devi ricostruirti lo stato dlle combo in base ai cambiamenti che hai fatto sul client.

HTH
.

Nothing can be born from hartred

Stefano (SM15455) Mostarda
http://blogs.aspitalia.com/SM15455
Rome Italy
3.939 messaggi dal 28 gennaio 2003
Ragiono con l'esempio classico REGIONI-PROVINCE, che è molto simile a "ciao Mondo!" come primo programma


Nel mio esempio, il pulsante submit che aggiorna la pagina, lancia due procedure, fillRegioni() e fillProvincie()

Il primo valorizza una lista di regioni leggendo da database (non uso il viewstate) e la regione selezionata viene valorizzata dal suo codice letto con Request.Form...

La seconda valorizza le province di quella regione lette sempre da database. La provincia selezionata viene valorizzata anche qui con Request.Form...

Sono stato sintetico, ma spero che basti: nel caso ho il codice di esempio.
119 messaggi dal 03 giugno 2003
Forse un po troppo sintentico ... ma grazie 1000 cmq. riesci a farmi avere il codice di esempio ???
Grazie ancora
3.939 messaggi dal 28 gennaio 2003
da prendere per quello che è: un semplice esercizio.

pagina aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="regioni_provincie.aspx.vb" Inherits="CorsoApogeo_ajax_ajax_in_action_regioni_provincie" %>

<!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 runat="server">
    <title>Pagina senza titolo</title>
    <link href="../../../stili/Styles.css" type="text/css" rel="stylesheet"/>

    <script src="../../../js/new_Ajax.js" type="text/javascript"></script>

    <script type="text/javascript">
<!--
function ListBox_regioni_onchange_get(v)
{
  document.getElementById("regioni").disabled = true;
  var j = new Ajax("?ajax_comando=provincie&codice_istat_regione=" + v.value, onload, null, onerror );

  function onload()
  {
      var t = this.request.responseText;
      //var tx = this.request.responseXML;
      
      document.getElementById("div1").innerHTML = t;
      document.getElementById("regioni").disabled = false;
  }

  function onerror()
  {
    document.getElementById("regioni").disabled = false;
    this.defaultError();
  }

}




//-->
    </script>

</head>
<body>
    <form id="Form1" method="post" runat="server">
        <table>
            <tr>
                <td style="width: 146px">
                    Regioni</td>
                <td>
                    provincie</td>
            </tr>
            <tr>
                <td valign="top" style="width: 146px">
                    <asp:ListBox ID="regioni" runat="server" Rows="20" onchange="ListBox_regioni_onchange_get(this);" Width="208px" EnableViewState="false" />
                </td>
                <td valign="top" width="400">
                    <div id="div1">
                        <asp:ListBox ID="provincie" runat="server" Rows="20" Width="224px" EnableViewState="false" />
                    </div>
                </td>
            </tr>
        </table>
        <div>
            <asp:Button ID="Button1" runat="server" Text="Refresh"></asp:Button></div>
        <asp:Label ID="label1" runat="server" />
    </form>
</body>
</html>




codice
Option Strict On
Partial Class CorsoApogeo_ajax_ajax_in_action_regioni_provincie
    Inherits System.Web.UI.Page

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Inserire qui il codice utente necessario per inizializzare la pagina

        Dim ajax_comando$ = RequestParams("ajax_comando")
        If ajax_comando = "provincie" Then
            AJAXfillProvincie()
        End If

        If Not Me.IsPostBack Then
            Libreria.FillListControl(Me.regioni, StringaConnessioneTest, "regioni", "nome_regione", "codice_istat_regione")
        End If
    End Sub

    Private Sub fillRegioni()
        Libreria.FillListControl(Me.regioni, StringaConnessioneTest, "regioni", "nome_regione", "codice_istat_regione")
        Libreria.SelectItemFromValue(Me.regioni, RequestParams("regioni"))
    End Sub


    Private Sub AJAXfillProvincie()
        Dim msg$ = ""
        Dim sql$ = ""
        Try
            Dim g As New ListBox
            g.ID = "provincie"
            g.Width = Unit.Pixel(224)
            g.Rows = 20
            sql = String.Format("SELECT NOME_PROVINCIA AS PROVINCIA FROM Q_PROVINCIE WHERE CODICE_ISTAT_REGIONE = ""{0}""", RequestParams("codice_istat_regione"))
            Libreria.FillListControl(g, StringaConnessioneTest, sql, "PROVINCIA", "PROVINCIA")

            Dim tw As New System.IO.StringWriter
            Dim hw As New System.Web.UI.HtmlTextWriter(tw)
            g.RenderControl(hw)

            msg = tw.ToString()

        Catch ex As Exception
            msg = "Errore - " & ex.Message

        Finally
            Response.Clear()
            Response.Write(msg)
            Response.End()
        End Try

    End Sub

    Private Sub fillProvincie()
        Dim msg$ = ""
        Dim sql$ = ""
        Try
            sql = String.Format("SELECT NOME_PROVINCIA AS PROVINCIA FROM Q_PROVINCIE WHERE CODICE_ISTAT_REGIONE = ""{0}""", RequestParams("regioni"))
            Libreria.FillListControl(Me.provincie, StringaConnessioneTest, sql, "PROVINCIA", "PROVINCIA")
            Libreria.SelectItemFromValue(Me.provincie, RequestParams("provincie"))

        Catch ex As Exception
            msg = "Errore - " & ex.Message

        Finally

        End Try

    End Sub

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        fillRegioni()
        fillProvincie()
    End Sub

End Class

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.