简体   繁体   English

C#/ ASP.NET / JS-onclick事件显示行,回发隐藏行

[英]C#/ASP.NET/JS - onclick event shows row, postback hides row

rbnResubmission.Items.FindByValue("Yes").Attributes.Add("onclick", "getCheckedRadioFieldResubmission(this)");
rbnResubmission.Items.FindByValue("No").Attributes.Add("onclick", "getCheckedRadioFieldResubmission(this)");

So I have these click events for showing rows in a table - that part works fine. 所以我有这些单击事件,用于在表中显示行-该部分工作正常。

Here's an example of what the code does (I'm not showing the "No" option) 这是代码功能的示例(我没有显示“否”选项)

function getCheckedRadioFieldResubmission(radio){
    if(radio.value == "Yes"){
         document.getElementById('<%=ApprovingInstituteRow.ClientID%>').style.display ="block";
         document.getElementById('<%=ApprovalNumberRow.ClientID%>').style.display ="block";
         document.getElementById('<%=IRBApprovalRow.ClientID%>').style.display ="block";
         document.getElementById('<%=ExpectedDateRow.ClientID%>').style.display ="none";
     }
}

The form needs to go through validation, and if there's any problems, because the event to show these rows only happens from "onclick" - they will disappear upon postback. 表单需要进行验证,如果有任何问题,因为显示这些行的事件仅发生在“ onclick”上-它们将在回发后消失。 what can I change to make them appear permanently? 我该如何更改以使其永久显示?

I'm guessing you're databinding the radio button list during onLoad. 我猜你在onLoad期间绑定了单选按钮列表。 You have to rebind it on postback. 您必须在回发时重新绑定它。

You'll probably want to add the same functionality of your getCheckedRadioFieldResubmission function into the onload event of the html <body> tag. 您可能需要将与getCheckedRadioFieldResubmission函数相同的功能添加到html <body>标记的onload事件中。 However, since the this object will refer to the body element and not the radio, you'll need to put something of this sort in there to find the radio: 但是,由于this对象将引用body元素而不是无线电,因此您需要在其中放置某种东西才能找到无线电:

var radio = document.getElementById('radio_id');

This will work if your radio list has a maintained state. 如果您的单选列表处于维护状态,这将起作用。 As in, it keeps it's state after Post Back. 与之类似,它保持“回发”后的状态。

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

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