简体   繁体   English

jQuery触发器asp.net单选按钮在更新面板内部单击

[英]jQuery trigger asp.net radiobutton click inside of update panel

I have some code where the user selects a 'Package' which is highlighted via jquery. 我有一些代码,用户可以在其中选择通过“ jQuery”突出显示的“包”。 How can i cause the asp radiobutton in this div to be clicked and perform its `OnCheckChanged' event? 如何使该div中的asp单选按钮被单击并执行其“ OnCheckChanged”事件?

$(document).ready(function () {
        $(".package-container").click(function (event) {
            $(this).closest('.radio-group-row').find('.package-title').removeClass('highlight');
            $(this).closest('.radio-group-row').find('.package-footer').removeClass('highlight');
            $(this).find('input:radio').prop('checked', true).click();
            $(this).find('.package-title').addClass('highlight');
            $(this).find('.package-footer').addClass('highlight');
        });
    });

I have tried this code using the onclick() method but it continually loads the page inside of the network tab in chrome is keeps posting the page and eventually lags out without a refresh. 我已经使用onclick()方法尝试了此代码,但是它会不断在chrome的网络标签中加载该页面,该页面会不断发布并最终导致页面刷新而无法刷新。

My radiobutton in question is this: 我的单选按钮是这样的:

<EclipseUI:CustomRadioButton runat="server" ID="RadioButton_Item" ClientIDMode="AutoID" ToolTip='<%# Eval("SystemValue") %>' GroupName="Package" OnCheckedChanged="RadioButton_Package_OnCheckedChanged" AutoPostBack="True"/>

How can i make jquery perform the oncheckedchange event of this radiobutton? 我如何使jquery执行此单选按钮的oncheckedchange事件?

Edit 编辑

$(document).ready(function () {
        $(".package-container").click(function (event) {
            $(this).closest('.radio-group-row').find('.package-title').removeClass('highlight');
            $(this).closest('.radio-group-row').find('.package-footer').removeClass('highlight');
            $(this).find('input:radio').prop('checked', true).click();
            $(this).find('.package-title').addClass('highlight');
            $(this).find('.package-footer').addClass('highlight');
        });
    });



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

    prm.add_endRequest(function (event) {
        var currPackage = $("#HF_Package").val();

        $("#" + currPackage).closest('.radio-group-row').find('.package-title').removeClass('highlight');
        $("#" + currPackage).closest('.radio-group-row').find('.package-footer').removeClass('highlight');
        $("#" + currPackage).find('input:radio').prop('checked', true);
        $("#" + currPackage).find('.package-title').addClass('highlight');
        $("#" + currPackage).find('.package-footer').addClass('highlight');
    });

My full jquery code looks like this. 我完整的jquery代码看起来像这样。 The latter part is for the postback to ensure their selected package is highlighted, i get this value from a hidden field and find the div of this value which is the package. 后一部分用于回发,以确保突出显示他们选择的包,我从隐藏字段中获取此值,然后找到该值的div(即包)。

in update panel your DOM elements are replaced with content returned from async postback so event binding is reset. 在更新面板中,您的DOM元素将替换为异步回发返回的内容,因此将重置事件绑定。

you need to attach event handlers on 2 events : 您需要在2个事件上附加事件处理程序:

(function($){ 

  var bindEvents =  function(){
   // bind events here;
  };

  // initial load
  $(document).ready( bindEvents);

  // every async load by update panel
  Sys.WebForms.PageRequestManager.getInstance().add_endRequest(bindEvents);

})(jQuery);  

for triggering postback, try adding button (you can hide it with css (disply:none) if you don't to display it) then add that button as updatepanel async trigger and call _dopostback and pass that button id 要触发回发,请尝试添加按钮(如果不显示,则可以用css隐藏它(disply:none)),然后将该按钮添加为updatepanel异步触发器,并调用_dopostback并传递该按钮id

__doPostBack('<%= TheButton.ClientID %>', '');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM