【问题标题】:ASP.Net checkbox postback doesn't fireASP.Net 复选框回发不会触发
【发布时间】:2015-07-16 20:37:41
【问题描述】:

我正在通过 JS 对现有的 ASP.Net 应用程序进行更改。我无法查看或编辑原始 ASP.Net 代码。我能做的就是将 JS 注入网页。有两个单选按钮,我想将默认值从一个更改为另一个,我可以通过 JS 轻松完成。 But when using the web app, when the other radio is chosen I can easily see there is a server post back happening and my JS code to toggle the checkbox does not fire this.因此,某些服务器端功能无法运行以允许我提交表单。

这里仅供参考,我的 JS 代码可以正常工作,这里没有什么要解决的问题。但即使在 Chrome 中检查收音机后,我也看不到任何事件被触发。我可能不完全了解如何检查 chrome 中的元素,有什么建议吗?

$(window).load(function() {
    // this tests for the selected value
    if ($("input[name*='radShippingAddressList']:checked").val() == "radSelectAddress") {

     // this changes the radio button
         $("input[name*='radShippingAddressList'][value='radAsBilling']").prop("checked", true);
    }
});

【问题讨论】:

  • 您需要在复选框上调用 click 方法,以便进行回发并运行服务器端代码。尝试这样做,而不是将检查设置为 true:$("input[name*='radShippingAddressList'][value='radAsBilling']").click();
  • @HaukurHaf 感谢它的工作并导致默认回发发生。请将此作为对我的问题的答案重新发布,以便我将其标记为已回答并让您获得代表。
  • 完成。很高兴我能帮忙:-)

标签: javascript asp.net google-chrome postback


【解决方案1】:

您需要在复选框上调用 click 方法,以便进行回发并运行服务器端代码。尝试这样做,而不是将检查设置为 true:

$("input[name*='radShippingAddressList'][value='radAsBilling']").click();

【讨论】:

    【解决方案2】:

    必须启用控件上的自动回发才能使道具更改影响回发。

    AutoPostBack="True"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-17
      • 2013-10-10
      相关资源
      最近更新 更多