下拉列表中的可见文本框所选值,不包含autopostback true [英] visible textbox on dropdown selected value with out autopostback true
问题描述
大家好,
我有2个下拉菜单和2个文本框,例如drp1,drp2,txt1,txt2.
我想当我从drp1中选择一个值时,txt1将可见,设置为true.当我从drp2中选择一个值后,txt2将可见.但是当我从drp1 txt1中选择一个值可见后,当我选择了drp2值txt2可见但txt1可见性为false时,出现了一些错误.所有这些都将在autopostback true上设置.我可以使用autopostback TRUE做到这一点吗?
请帮忙!!!!!!
hi guys,
i have a 2 drop down and 2 text box like drp1, drp2, txt1,txt2.
i want when i selected a value from drp1 then txt1 will be visible set true. and after when i slect a value from drp2 then txt2 will be visible. but i got some error when i select a value from drp1 txt1 is visible after it when i selected a drp2 value txt2 is visible but txt1 visibility will be false. that all will be set on autopostback true. can i do that with autopostback TRUE.
please help!!!!!!
推荐答案
嗨 我不明白是什么问题.您可以尝试以下代码:
Hi I didn''t understand what is the issue . Can you try the following code :
<body>
<form id="form1" runat="server">
<div>
<asp:dropdownlist id="DropDownList1" runat="server" autopostback="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged" xmlns:asp="#unknown">
<asp:listitem value="A">A1-Visible</asp:listitem>
<asp:listitem>B1-Visible</asp:listitem>
<asp:listitem>C1-Hide</asp:listitem>
</asp:dropdownlist>
<asp:dropdownlist id="DropDownList2" runat="server" autopostback="True" onselectedindexchanged="DropDownList2_SelectedIndexChanged" xmlns:asp="#unknown">
<asp:listitem>P1-Visible</asp:listitem>
<asp:listitem>Q1-Visible</asp:listitem>
<asp:listitem>R1-Hide</asp:listitem>
</asp:dropdownlist>
</div>
<asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown">TextBox1</asp:textbox>
<asp:textbox id="TextBox2" runat="server" xmlns:asp="#unknown">TextBox2</asp:textbox>
</form>
</body></body>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//If you are not setting the TextBox1 and TextBox2 visible property to false in designer[aspx page], you can use the following code to hide the text boxes on load.
DropDownList1.SelectedIndex = 2; // when page load happens TextBox1 will be invisible.
DropDownList2.SelectedIndex = 2; // when page load happens TextBox2 will be invisible
(DropDownList1 as IPostBackDataHandler).RaisePostDataChangedEvent();
(DropDownList2 as IPostBackDataHandler).RaisePostDataChangedEvent();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex.Equals(2))
TextBox1.Visible = false;
else
TextBox1.Visible = true;
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList2.SelectedIndex.Equals(2))
TextBox2.Visible = false;
else
TextBox2.Visible = true;
}
问候
多米尼克
Regards
Dominic
嗨
您是否检查了上面的代码?我认为,在该示例中,回发没有问题.
步骤0:默认情况下,两个TextBox都是可见的.
步骤1:选择"C1-Hide"(C1-Hide) TextBox1将是不可见的,TextBox2将是可见的
步骤2:选择"R1-Hide"(R1-Hide) TextBox1将不可见,TextBox2将不可见
步骤3:选择"A1-Visible"(A1-Visible)-> TextBox1将可见,TextBox2将不可见
步骤4:选择"P1-Visible"(P1-Visible)-> TextBox1将可见,TextBox2将可见
一遍又一遍
步骤5:选择"C1-Hide"-> TextBox1将是不可见的,TextBox2将是可见的
我认为所有方案都可以满足您的需求.
问候
多米尼克
Hi
Have you checked the above code ? I think , in that example there is no issue with postback.
Step0 : By default, both TextBox will be visible.
Step1 : Select ''C1-Hide'' --> TextBox1 will be invisible, TextBox2 will be visible
Step2 : select ''R1-Hide'' --> TextBox1 will be invisible, TextBox2 will be invisible
Step3 : Select ''A1-Visible'' -> TextBox1 will be visible, TextBox2 will be invisible
Step4 : Select ''P1-Visible'' -> TextBox1 will be visible, TextBox2 will be visible
and again
Step5 : Select ''C1-Hide'' -> TextBox1 will be invisible, TextBox2 will be visible
I think all the scenarios are satisfying here.What else you are looking for.
Regards
Dominic
这篇关于下拉列表中的可见文本框所选值,不包含autopostback true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!