C# 通过onselectIndexChange事件隐藏文本框

C# 通过onselectIndexChange事件隐藏文本框,c#,asp.net,updatepanel,C#,Asp.net,Updatepanel,在我的网站上,我有一个带有2个值的下拉列表。我试图编写此代码,通过onselectIndexChange事件隐藏文本框,而不刷新页面。 为了实现这一目标,我使用了更新面板,但在dropDownList select上,textboxs的可见性没有变化。 我的代码: <asp:Label ID="Label1" runat="server" Text="شخص :"></asp:Label></td> &l

在我的网站上,我有一个带有2个值的下拉列表。我试图编写此代码,通过onselectIndexChange事件隐藏文本框,而不刷新页面。 为了实现这一目标,我使用了更新面板,但在dropDownList select上,textboxs的可见性没有变化。 我的代码:

                <asp:Label ID="Label1" runat="server" Text="شخص :"></asp:Label></td>
            <td> 
                <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>
          </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>
                &nbsp;</td>
        </tr>
    </table>
     </ContentTemplate><Triggers>

                            </Triggers>  </asp:UpdatePanel>

حقیقی
حقوقی
.cs文件:

                <asp:Label ID="Label1" runat="server" Text="شخص :"></asp:Label></td>
            <td> 
                <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>
          </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>
                &nbsp;</td>
        </tr>
    </table>
     </ContentTemplate><Triggers>

                            </Triggers>  </asp:UpdatePanel>
受保护的无效页面加载(对象发送方,事件参数e)
{
pnlMname.Visible=false;
}
受保护的无效按钮1\u单击(对象发送者,事件参数e)
{
}
受保护的void DropDownList1\u SelectedIndexChanged(对象发送方,事件参数e)
{
如果(DropDownList1.SelectedValue==“if”
{
pnlMname.Visible=false;
pnlname.Visible=true;
}
else if(DropDownList1.SelectedValue==“حوقی”)
{
pnlname.Visible=false;
pnlMname.Visible=true;
}
}
试着这样做:

                <asp:Label ID="Label1" runat="server" Text="شخص :"></asp:Label></td>
            <td> 
                <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>
          </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>
                &nbsp;</td>
        </tr>
    </table>
     </ContentTemplate><Triggers>

                            </Triggers>  </asp:UpdatePanel>
在更新面板中使用所有代码

  <asp:UpdatePanel ID="UpdatePanel1" runat="server">
               <ContentTemplate>

// All Controls Placed Here

</ContentTemplate><Triggers>

</Triggers>  </asp:UpdatePanel>
                <asp:Label ID="Label1" runat="server" Text="شخص :"></asp:Label></td>
            <td> 
                <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>
          </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>
                &nbsp;</td>
        </tr>
    </table>
     </ContentTemplate><Triggers>

                            </Triggers>  </asp:UpdatePanel>

//所有控件都放在这里
默认情况下,它将使用异步回发 代码:

                <asp:Label ID="Label1" runat="server" Text="شخص :"></asp:Label></td>
            <td> 
                <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>
          </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>
                &nbsp;</td>
        </tr>
    </table>
     </ContentTemplate><Triggers>

                            </Triggers>  </asp:UpdatePanel>

حقیقی
حقوقی