gpt4 book ai didi

javascript - 在 Page_Load 上禁用列表框

转载 作者:行者123 更新时间:2023-12-03 08:38:34 26 4
gpt4 key购买 nike

我试图在加载 Web 表单时禁用两个列表框,但列表框并未禁用。我尝试了下面的代码,但它仍然不适用于我的情况。请让我知道我哪里出错了。

设计师代码

<telerik:RadListBox ID="lbSelectedDepartmentContacts" runat="server" Width="220px" AutoPostBackOnTransfer="true" AutoPostBackOnReorder="true" AutoPostBackOnDelete="true" CheckBoxes="false" AllowTransfer="true" AllowTransferOnDoubleClick="true" TransferToID="lbDepartmentContacts"
Height="276px" SelectionMode="Single" AllowReorder="True">
<ButtonSettings ShowTransfer="false" ShowTransferAll="false" ReorderButtons="Common" ShowReorder="true" />
</telerik:RadListBox>
</td>
</tr>
<tr>
<td align="right">
<telerik:RadListBox ID="lbDepartmentContacts" runat="server" Width="200px" CheckBoxes="false" AutoPostBackOnTransfer="true" AllowTransfer="true" AllowTransferOnDoubleClick="true" TransferToID="lbSelectedDepartmentContacts"
Height="250px" SelectionMode="Single">
<ButtonSettings TransferButtons="Common" ShowTransfer="false" ShowTransferAll="false" />
</telerik:RadListBox>

回溯代码

public void DisableControls()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@"<script language='javascript'>function DisableControls(){");
sb.Append(@"var lbl = document.getElementById('lbSelectedDepartmentContacts').disabled = true;");
sb.Append(@" var Txt = document.getElementById('txtDepartmentCategoryContactsFilter').disabled = true;");
sb.Append(@" var btn = document.getElementById('RadButton1').disabled = true;");

sb.Append("}</script>");

if (!ClientScript.IsClientScriptBlockRegistered("JSScriptBlock"))
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "JSScriptBlock",
sb.ToString());
}

string funcCall = "<script language='javascript'>DisableControls();</script>";

if (!ClientScript.IsStartupScriptRegistered("JSScript"))
{
ClientScript.RegisterStartupScript(this.GetType(), "JSScript", funcCall);
}
}

还尝试过:

Page.ClientScript.RegisterStartupScript(this.GetType(), "text", "DepartmentLoad();", true);

JavaScript 代码

function DepartmentLoad(){
document.getElementById("lbSelectedDepartmentContacts").disabled = true;
document.getElementById("lbDepartmentContacts").disabled = true;
document.getElementById("txtDepartmentCategoryContactsFilter").disabled = true;
ducument.getElementById("RadButton1").disabled = true;}

最佳答案

仅使用 C# 方法来禁用 2 个列表框...

删除或注释掉现有的 DisableControls() 方法,然后添加以下内容...

protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack) return;
DisableControls();
}

private void DisableControls()
{
lbSelectedDepartmentContacts.Enabled = lbDepartmentContacts.Enabled = false;
}

关于javascript - 在 Page_Load 上禁用列表框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33122679/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com