我的za.aspx页面中有一个服务器端div标签,其中包含标签和下拉列表
<div id="SkillsStatus" runat="server" style="display:none">
<asp:Label ID="Label1" runat="server" Text="Please select a skill"
Font-Bold="True" Font-Italic="False" Font-Size="Larger"></asp:Label>
<asp:DropDownList ID="SkillsStatusddl" runat="server" AutoPostBack="True"
onselectedindexchanged="SkillsStatusddl_SelectedIndexChanged"
CssClass="selectpicker">
<asp:ListItem Value="0">Choose An Option</asp:ListItem>
</asp:DropDownList>
现在,我将数据绑定到codebehind文件的dropdownlist,我在文件后面的代码中绑定了一个cusom控件
PreChatSurvey customPrechatSurvey = new PreChatSurvey
{
ID = "customPrechatSurvey",
ForeColor = Color.Black,
SurveyId = 0,
IsPreview = false
};
protected override void OnInit(EventArgs e)
{
SkillsStatus.Attributes.Add("style", "display:block");
SkillsStatusddl.DataSource = "";
orgID = Convert.ToInt32(Request.QueryString["OrgID"]);
DataSet ds = SubCampaignBase.GetSkillStatus(orgID);
DataTable dt = ds.Tables[0];
foreach (DataRow row in dt.Rows)
{
ListItem li = new ListItem();
li.Text = row["SubCampaignName"].ToString();
li.Value = row["SubCampaignId"].ToString();
li.Attributes.Add("data-icon", "glyphicon glyphicon-user");
if (Convert.ToBoolean(row["soa_status"]))
{
li.Attributes.CssStyle.Add(HtmlTextWriterStyle.Color, "green");
li.Attributes.CssStyle.Add(HtmlTextWriterStyle.BackgroundColor, "white");
}
else
{
li.Attributes.CssStyle.Add(HtmlTextWriterStyle.Color, "black");
li.Attributes.CssStyle.Add(HtmlTextWriterStyle.BackgroundColor, "white");
}
SkillsStatusddl.Items.Add(li);
}
base.OnInit(e);
}
现在它在同一页面上加载自定义控件和下拉列表,这个自定义控件有一个按钮,点击该按钮,我想隐藏包含下拉列表的div标签,所以我按下按钮点击
private void btnSubmit_Click(object sender, EventArgs e)
{
DropDownList dd = (DropDownList)this.Parent.FindControl("SkillsStatusddl");
dd.Enabled = false;
HtmlGenericControl div = (HtmlGenericControl)this.Parent.FindControl("SkillsStatus");
div.Attributes.Add("style", "display:none");
}
为了安全起见,我尝试了两件事, 但没有任何工作,div既不会消失也不会下拉被禁用