C# 从asp.net中的代码隐藏中删除属性
我有一个网格,希望根据代码隐藏中的条件添加或删除disable属性 以下是jquery代码:C# 从asp.net中的代码隐藏中删除属性,c#,jquery,asp.net,webforms,C#,Jquery,Asp.net,Webforms,我有一个网格,希望根据代码隐藏中的条件添加或删除disable属性 以下是jquery代码: $("#myGrid tbody :input").attr("disabled", "disabled"); 我想从代码背后做同样的事情。我在#myGrid元素中提到了“runat=server”。在代码隐藏中,我尝试了以下方法: if (condition-here) { myGrid .Attributes.Remove("disabled"); } else { myGrid.At
$("#myGrid tbody :input").attr("disabled", "disabled");
我想从代码背后做同样的事情。我在#myGrid元素中提到了“runat=server”。在代码隐藏中,我尝试了以下方法:
if (condition-here)
{
myGrid .Attributes.Remove("disabled");
}
else
{
myGrid.Attributes.Add("disabled","disabled");
}
您正在尝试禁用/启用网格中的所有输入。如果您使用AJAX并需要它来更新面板,我们可以通过使用ScriptManager来实现这一点,然后: 所以,基本上你的代码应该是:
if (condition-here)
{
//remove attribute
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "MyScript", "$('#myGrid tbody :input').removeAttr('disabled');", true);
}
else
{
//add attribute
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "MyScript", "$('#myGrid tbody :input').attr('disabled', 'disabled');", true);
}
如果不使用AJAX,请使用以下方法:
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", "$('#myGrid tbody :input').attr('disabled', 'disabled');", true);