0
在我的網站中,我有一個包含2個值的下拉列表。我試圖編寫這段代碼來隱藏文本框的onselectIndexChange事件,而不刷新頁面。 爲此目標我使用更新面板但dropDownList選擇沒有更改文本框的可見性。 我的代碼:通過onselectIndexChange事件隱藏文本框
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<table dir="rtl">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="شخص :"></asp:Label></td>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" EnableViewState="true" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Selected="True">حقیقی</asp:ListItem>
<asp:ListItem>حقوقی</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
<asp:Panel ID="pnlname" runat="server">
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="نام و نام خانوادگی : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtname" runat="server" Width="415px"></asp:TextBox>
</td>
</tr>
</asp:Panel>
<asp:Panel ID="pnlMname" runat="server">
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="نام و نام خانوادگی مسئول : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtmname" Width="415px" runat="server"></asp:TextBox>
</td>
</tr>
</asp:Panel>
<tr>
<td>
<asp:Label ID="Label4" runat="server" Text="شماره قرارداد : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtIdgharardad" Width="415px" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label7" runat="server" Text="علت درخواست اعزام کارشناس : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtellat" Width="415px" runat="server" Height="194px" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label5" runat="server" Text="شماره همراه : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtNumber" Width="415px" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label6" runat="server" Text="شماره ثابت : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtSnumber" Width="415px" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="ثبت درخواست" />
</td>
<td> </td>
</tr>
</table>
cs文件:
protected void Page_Load(object sender, EventArgs e)
{
pnlMname.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "حقیقی")
{
pnlMname.Visible = false;
pnlname.Visible = true;
}
else if (DropDownList1.SelectedValue == "حقوقی")
{
pnlname.Visible = false;
pnlMname.Visible = true;
}
}
這樣的感謝。有用 –