2013-05-07 111 views
1

我有一個用戶控件使用updatepanel。當頁面第一次加載按鈕點擊工作正常,並顯示在一個DIV ...當我再次搜索並點擊按鈕,單擊事件不會觸發,即使頁面加載事件也不會觸發。當您輸入郵政編碼時,我正在使用Google地理編碼查找最近的商店。我懷疑它是與JavaScript或頁面驗證不讓按鈕點擊事件。這是我的代碼。服務器端按鈕點擊事件沒有內部UpdatePanel

ASPX頁面

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ClickAndCollect.ascx.cs" 
     Inherits="ConLib_Custom_ClickAndCollect" %> 
<%@ Register Assembly="CommerceBuilder.Web" Namespace="CommerceBuilder.Web.UI.WebControls" 
     TagPrefix="cb" %> 
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %> 
<script src="/js/jquery-1.9.1.min.js" type="text/javascript"></script> 
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false" type="text/javascript"></script> 
<script src="/js/ClickAndCollectGeoCoding.js" type="text/javascript"></script> 
<asp:UpdatePanel ID="ClickAndCollectUpdatePanel" runat="server" UpdateMode="Always"> 
     <ContentTemplate> 
     <div class="ClickAndCollectPanelTitle"> 
      Click and Collect 
      <p> 
        Your order will be available to collect in store in 24 - 72 hours 
        <br /> 
        We will email you as soon as your order is ready for collection 
      </p> 
     </div> 
     <div class="errorPostcodeSummaryDiv"> 
       <asp:Label ID="errorPostcodeSummary" Text="" runat="server" Visible="false" CssClass="errorPostcodeSummary"> 
       </asp:Label> 
     </div>   
     <div class="ClickAndCollectContainer"> 
       <div class="ClickAndCollectContents"> 
        <div class="ClickAndCollectHeader"> 
         <asp:Label ID="ClickAndCollectDesc" runat="server" Text="Find your nearest store" CssClass="ClickAndCollectDesc"></asp:Label> 
         <asp:TextBox ID="ClickAndCollectTextBox" runat="server" Text="" ToolTip="Enter Your Postcode" CssClass="ClickAndCollectTextBox"></asp:TextBox> 
         <ajax:TextBoxWatermarkExtender ID="ClickAndCollectTextWatermark" runat="server" TargetControlID="ClickAndCollectTextBox" WatermarkText="Postcode or Town" WatermarkCssClass="watermark"></ajax:TextBoxWatermarkExtender> 

         <asp:Button ID="ClickAndCollectSubmit" runat="server" CssClass="ClickAndCollectSubmit" Text="Find Stores" onClick= "ClickAndCollectSubmit_Click"/> 
         <asp:RequiredFieldValidator ID="ClickAndCollectTextBoxValidator" runat="server" ValidationGroup="OPC" 
           ControlToValidate = "ClickAndCollectTextBox" CssClass="ClickAndCollectValidatorError" 
           ErrorMessage = "Please enter valid address to search for the nearest stores." Text="*"> 
           </asp:RequiredFieldValidator> 
        </div> 
        <div class="ClickAndCollectResult"> 
         <asp:Panel ID="ClickAndCollectResultPanel" Visible="false" CssClass="ClickAndCollectResult" 
          runat="server"> 
          <div class="ClickAndCollectResultHeader"> 
           Choose your nearest store 
          </div> 
          <div class="ClickAndCollectResultTable"> 
           <asp:RadioButtonList ID="StoresRadioList" Visible="false" runat="server" ToolTip="Choose your nearest store" CssClass="ClickAndCollectResultRadios" ValidationGroup="OPC" onselectedindexchanged="StoresRadioList_SelectedIndexChanged" AutoPostBack="true"> 
           </asp:RadioButtonList> 
           <asp:RequiredFieldValidator ID="StoresRadioValidator" runat="server" ControlToValidate = "StoresRadioList" Text ="*" CssClass="ClickAndCollectValidatorError" ErrorMessage = "Please choose one store for your delivery."> 
           </asp:RequiredFieldValidator> 
          </div> 
         </asp:Panel> 
        </div> 
        <div class="selectedAddress"> 
         <asp:PlaceHolder ID="selectedStore" runat="server"></asp:PlaceHolder> 
        </div> 
        <asp:HiddenField ID="latValue" runat="server"/> 
        <asp:HiddenField ID="lanValue" runat="server"/> 
        <asp:HiddenField ID="statusCode" runat="server"/> 
       </div> 
      </div> 
     </ContentTemplate> 
</asp:UpdatePanel> 

JS文件

var address; 
var region; 

var prm = Sys.WebForms.PageRequestManager.getInstance(); 
prm.add_endRequest(EndRequestHandler); 

function EndRequestHandler(sender, args) { 
     if (args.get_error() == undefined) { 
      AttachEventAfterPostback(); 
     } 
} 

function AttachEventAfterPostback() { 
     $(document).ready(function() { 
      address = $('.ClickAndCollectTextBox').val(); 
      if (address.length != 0) { 
        checkAddress(address); 
        getLatLong(address, region); 

      } 
      $('.ClickAndCollectTextBox').on('blur', function() { 
        address = $('.ClickAndCollectTextBox').val(); 
        if (address.length != 0) { 
         checkAddress(address); 
         getLatLong(address, region); 
        } 
      }); 
     }); 
} 

function getLatLong(address, region) { 
      var geocoder = new google.maps.Geocoder(); 
      var result = ""; 
      geocoder.geocode({ 
        'address': address, 
        'region': region 
      }, function (results, status) { 
        if (status == google.maps.GeocoderStatus.OK) { 
         $("[id$='statusCode']").val("OK"); 
         $("[id$='latValue']").val(results[0].geometry.location.lat()); 
         $("[id$='lanValue']").val(results[0].geometry.location.lng()); 
         //      if (typeof (callback) == "function") { 
         //        callback(); 
         //      } 
        } else { 
         $("[id$='statusCode']").val("ZERO_RESULTS"); 
         $("[id$='latValue']").val("0"); 
         $("[id$='lanValue']").val("0"); 
        } 
      }); 
     } 

AttachEventAfterPostback(); 

function checkAddress(inputAddress) { 
     switch (inputAddress.toUpperCase()) { 
      //some code 
     } 
} 

*編輯***

「我在做什麼作爲用戶輸入郵政編碼和文本框的損失,儘快爲焦點,我打電話給geocode讓LAT和LNG值在隱藏字段中準備就緒。只要用戶點擊,點擊事件fir e在服務器上並使用RadiobuttonList顯示結果。儘快用戶選擇一個廣播,一個div顯示他們選擇的商店的細節。現在讓我們說,如果他們不選擇一個收音機,並嘗試輸入差異郵政編碼,然後按鈕單擊不工作。但如果他們選擇一個電臺,然後嘗試差異郵編,按一下按鈕工作正常..

任何人有任何想法,爲什麼這種情況正在發生......

+0

後的每一件事情,你是否嘗試過通過這一個開發者控制檯(在許多瀏覽器F12)步進?另外,您是否收到您可以給我們的錯誤信息? – 2013-05-07 15:50:06

+0

控制檯中沒有錯誤消息。我已經嘗試過這在鉻和每當我把警報使用jQuery的那個按鈕,它顯示我一個警戒窗口,但不知何故它不是射擊服務器端按鈕點擊事件.. – 2013-05-07 15:54:29

回答

1

要附加在錯誤的方式活動。

更新面板會進行部分頁面回發,並且在您手動刷新頁面之前不會處於文檔準備就緒狀態。

刪除AttachEventAfterPostback寫在頁面加載函數代碼這樣它西港島線自動重新綁定每一個局部回傳

function pageLoad(sender,args){ 
    address = $('.ClickAndCollectTextBox').val(); 
    if (address.length != 0) { 
     checkAddress(address); 
     getLatLong(address, region); 

    } 
    $('.ClickAndCollectTextBox').on('blur', function() { 
     address = $('.ClickAndCollectTextBox').val(); 
      if (address.length != 0) { 
       checkAddress(address); 
       getLatLong(address, region); 
      } 
     }); 
} 
+0

這是一個很好的...我已經作出相應的變化但仍然不起作用 – 2013-05-07 16:22:07

+0

您是否嘗試過在pageload之後逐行記錄模糊事件的信息行。並調試哪一行導致錯誤.. – writeToBhuwan 2013-05-07 16:25:39

+0

是的,我已經試過..我每次記錄經緯度,每次文本框損失焦點,並返回與狀態確定值。我不知道爲什麼會發生這種情況.. – 2013-05-07 16:36:04

相關問題