如何通过单击单选按钮使文本框中的数据消失?

时间:2017-01-05 03:16:39

标签: c# asp.net

我有这个表单,其中有一个下拉列表。当用户选择列表时,相应的数据出现在文本框中。

现在,如果用户点击单选按钮,我需要让数据消失 - 在该部分中是;不是当用户点击表格末尾的提交时。

下面的代码不会使数据消失。

这是我尝试过的代码:

protected void OtherVendor_SelectedIndexChanged(object sender, EventArgs e)
{
    // use User entered infor - use Insert ?
    if (OtherVendor.Text == "Yes")
    {
        txtSupplierEmail.Text = string.Empty;
        txtSupplierName.Text = string.Empty;
        txtSupplierName.Text = string.Empty;
        txtSupplierCttPerson.Text = string.Empty;
        txtSupplierCttNumber.Text = string.Empty;
        txtSupplierEmail.Text = string.Empty;
        txtSupplierName.Text = string.Empty;
        txtSupplierCttPerson.Text = string.Empty;
        txtSupplierCttNumber.Text = string.Empty;           
    }           
}

我的HTML代码:

<div class="row">
    <div class="col-lg-12">
        <div id="divAP"
             class="panel panel-primary">
            <div class="panel-heading">Supplier Information</div>
            <div class="panel-body">
                <div class="col-sm-6 col-lg-6">
                    <asp:UpdatePanel ID="UpdatePanel4"
                                     runat="server">
                        <ContentTemplate>
                            <div class="form-group row">
                                <label class="col-md-4 control-label"
                                       for="inputRefNo">Vendor :
                                    <span style="color: red">*</span>
                                </label>
                                <div class="input-group col-md-8">
                                    <asp:DropDownList ID="ddlSupplier"
                                                      OnSelectedIndexChanged="ddl1_SelectedIndexChanged"
                                                      runat="server"
                                                      CssClass="form-control"
                                                      AutoPostBack="true"></asp:DropDownList>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-md-4 control-label"
                                       for="radios">Others Vendor
                                    <span style="color: red">*</span>
                                </label>
                                <div class="col-md-4">
                                    <label class="col-md-4 control-label">
                                        <asp:RadioButtonList ID="OtherVendor"
                                                             runat="server"
                                                             OnSelectedIndexChanged="OtherVendor_SelectedIndexChanged"
                                                             RepeatColumns="2"
                                                             RepeatDirection="Horizontal"
                                                             AutoPostBack="true">
                                            <asp:ListItem Text="Yes"
                                                          value="Yes"></asp:ListItem>
                                            <asp:ListItem Text="No"
                                                          value="No"></asp:ListItem>
                                        </asp:RadioButtonList>
                                    </label>
                                </div>
                                <%--To insert code for letting user filling up Supplier email - to have auto-pop up and enable overwrite etc. --%>
                            </div>
                            <div class="form-group row">
                                <label class="col-md-4 control-label"
                                       for="inputRefNo">Vendor Email:
                                    <span style="color: red">*</span>
                                </label>
                                <div class="col-md-4 control-label"
                                     for="inputRefNo">
                                    <asp:TextBox ID="txtSupplierEmail"
                                                 runat="server"
                                                 Text="Label"
                                                 Width="100%"
                                                 CssClass="form-control"></asp:TextBox>
                                </div>
                            </div>
                        </ContentTemplate>
                    </asp:UpdatePanel>

1 个答案:

答案 0 :(得分:1)

我不确定它是否是拼写错误,无论如何,在您的标记中,您被指定为AutoPostBck,但实际上它应该是AutoPostBack;这意味着Bck应为Back

还有一个建议,您可以将条件格式化为:

,而不是在条件中使用OtherVendor.Text
 if (OtherVendor.SelectedValue == "Yes")
 {
    // Clear controls here
 }
 else
 { 
   // Do something else
 }