Hello,
I'm trying to do one page with two listboxes that filers one grid.
The problem is that Load event fires twice.
First time all parameters are transmitted correctly.
The second time the whole QueryString disappears!!
ASPX Directive:
ASPX Code:
<asp:listbox clientidmode="Static" id="LstTipo" style="width:150px;height:100px;" runat="server" datasourceid="SqlDataSource2" datatextfield="FLD_RESULTADO" datavaluefield="FLD_RESULTADO">
<asp:listbox clientidmode="Static" id="LstTMA" style="width:150px;height:100px;" runat="server" datasourceid="SqlDataSource4" datatextfield="FLD_MOD3" datavaluefield="FLD_MOD3">
I'm trying to do one page with two listboxes that filers one grid.
The only requirement is that the selection made by the user must be reflected in the URL so that it can be sent by mail to colleagues with the selection already made
The problem is that Load event fires twice.
First time all parameters are transmitted correctly.
The second time the whole QueryString disappears!!
ASPX Directive:
<%@PageLanguage="vb"uiCulture="en-US"culture="de-DE"MasterPageFile="XTAB_WO.master"AutoEventWireup="false"CodeFile="LC1vsLC2.vb"Inherits="LC1vsLC2"ClientIDMode="Predictable"%>
ASPX Code:
<asp:listbox clientidmode="Static" id="LstTipo" style="width:150px;height:100px;" runat="server" datasourceid="SqlDataSource2" datatextfield="FLD_RESULTADO" datavaluefield="FLD_RESULTADO">
<asp:listbox clientidmode="Static" id="LstTMA" style="width:150px;height:100px;" runat="server" datasourceid="SqlDataSource4" datatextfield="FLD_MOD3" datavaluefield="FLD_MOD3">
<dx:ASPxGridView ID="gridview1" runat="server" AutoGenerateColumns="true" DataSourceID="SqlDataSource1"></dx:ASPxGridView><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyCCnn %>"></asp:SqlDataSource><asp:Button ID="Button1" runat="server" Text="Select" style="width:150px;" OnClientClick="Populate();"/><asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:hacheConnectionString %>" SelectCommand="select '(ALL)' FLD_RESULTADO UNION ALL select distinct FLD_RESULTADO from XXXXXXXXXXXXX"></asp:SqlDataSource><asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:hacheConnectionString %>" SelectCommand="select '(ALL)' FLD_MOD3 UNION ALL select distinct FLD_MOD3 from XXXXXXXXXXXXX"></asp:SqlDataSource><script type="text/javascript" language="javascript">function removeParam(key, sourceURL) {var rtn = sourceURL.split("?")[0], param, params_arr = [], queryString = (sourceURL.indexOf("?") !== -1) ? sourceURL.split("?")[1] : "";if (queryString !== "") { params_arr = queryString.split("&");for (var i = params_arr.length - 1; i >= 0; i -= 1) { param = params_arr[i].split("=")[0];if (param === key) { params_arr.splice(i, 1); } } rtn = rtn + "?" + params_arr.join("&"); }return rtn; } function Populate() {var tma = document.getElementById("LstTMA");var tipo = document.getElementById("LstTipo");var fe = "";var miurl="";var miurlIni="";var valor = ""; miurlIni = window.top.location.href + "?";if (tipo.selectedIndex >= 0) {var selectedtipo = tipo.options[tipo.selectedIndex].text; miurl = removeParam("tipo", miurl); valor = (selectedtipo == "(ALL)") ? '0' : selectedtipo; miurl = miurl + "&tipo=" + valor.replace(" ","_"); }if (tma.selectedIndex >= 0) {var selectedtma = tma.options[tma.selectedIndex].text; miurl = removeParam("tma", miurl); valor = (selectedtma == "(ALL)") ? '0' : selectedtma; miurl = miurl + "&tma=" + valor; }window.top.location.href = miurlIni + miurl.substring(1,999); }</script> CODE-BEHIND: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim q As String, q_count As String, x As Integer, NumR As Long Dim dv As Object Dim mpContentPlaceHolder As ContentPlaceHolder Dim ddlRp As ASPxRoundPanel Dim LstTipo As ListBox, StTipo As String Dim LstTMA As ListBox, StTma As String mpContentPlaceHolder = CType(Master.FindControl("ContentHolder"), ContentPlaceHolder) If Not mpContentPlaceHolder Is Nothing Then ddlRp = CType(mpContentPlaceHolder.FindControl("ASPxRoundPanel3"), ASPxRoundPanel) If Not ddlRp Is Nothing Then LstTipo = CType(ddlRp.FindControl("LstTipo"), ListBox) LstTMA = CType(ddlRp.FindControl("LstTMA"), ListBox) End If End If If Request.QueryString.Count > 0 AndAlso ((Not Request.QueryString("pais") Is Nothing) Or (Not Request.QueryString("y4m2d2") Is Nothing) Or (Not Request.QueryString("tipo") Is Nothing) Or (Not Request.QueryString("tma") Is Nothing)) Then StTipo = "" : StTma = ""': Sty4m2d2 = "" If Not (Request.QueryString("tipo") Is Nothing) AndAlso Request.QueryString("tipo").ToString() <> "" Then If Request.QueryString("tipo") = "0" Then LstTipo.SelectedValue = "(ALL)" StTipo = "" Else LstTipo.SelectedValue = Replace(Request.QueryString("tipo"), "_", " ") StTipo = " AND FLD_RESULT='"& Replace(Request.QueryString("tipo"), "_", "") & "'" End If End If If Not (Request.QueryString("tma") Is Nothing) AndAlso Request.QueryString("tma").ToString() <> "" Then If Request.QueryString("tma") = "0" Then LstTMA.SelectedValue = "(ALL)" StTma = "" Else LstTMA.SelectedValue = Replace(Request.QueryString("tma"), "_", " ") StTma = " AND FLD_MOD3='"& Replace(Request.QueryString("tma"), "_", "") & "'" End If End If q = "SELECT " & StFieldsQuery & " FROM V_BUDA_LC1vsLC2 WHERE 1=1 " & StTipo & StTma '& Sty4m2d2 '& " ORDER BY FLD_ID" q_count = "SELECT count(*) NumR FROM V_BUDA_LC1vsLC2 where 1=1 " & StTipo & StTma '& Sty4m2d2 SqlDataSource11.SelectCommand = q_count dv = CType(SqlDataSource11.Select(DataSourceSelectArguments.Empty), DataView) NumR = CType(dv.Table.Rows(0)(0), Integer) If (NumR > 0) Then SqlDataSource1.SelectCommand = q gridview1.Visible = True LblNoData.Visible = False Else gridview1.Visible = False LblNoData.Visible = True End If Else gridview1.Visible = True LblNoData.Visible = False q = "SELECT * FROM V_BUDA_LC1vsLC2 WHERE 1=0" SqlDataSource1.SelectCommand = q End If Page.DataBind() End Sub