在Asp .net中使用下拉列表和Panel可见问题更新Panel [英] Update Panel with drop down and Panel visible Issues in Asp .net
本文介绍了在Asp .net中使用下拉列表和Panel可见问题更新Panel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi Frnds,
以下代码我有两个Panel.Inside下拉更改事件我需要更改面板更改。但页面也刷新了如何不刷新。
< html xmlns = http://www.w3.org/1999/xhtml >
< head runat = server >
< title > < / title >
< / head >
< 正文 >
< 表格 id = form1 runat = server >
< asp:ScriptManager ID = ScriptManager1 runat = 服务器 >
< / asp:ScriptManager >
< div >
< asp:Panel ID = Panel1 runat = server >
< < span class =code-leadattribute> asp:UpdatePanel ID = UpdatePanel1 runat = server >
< ContentTemplate > ;
< asp:DropDownList ID = DropDownList1 runat = server AutoPostBack = True OnSelectedIndexChanged = DropDownList1_SelectedIndexChanged >
< asp:ListItem > 选择 < / asp:ListItem >
< asp:ListItem > Panel2 < / asp:ListItem >
< / asp:DropDownList >
< / ContentTemplate >
< 触发器 >
< asp:AsyncPostBackTrigger ControlID = DropDownList1 / >
< / Triggers >
< / asp:UpdatePanel >
< asp:TextBox ID = TextBox1 runat = server > < / asp:TextBox >
< asp:按钮 ID = btnP1 runat = 服务器 文字 = Panel1 OnClick < span class =code-keyword> = btnP1_Click / >
< / asp:Panel >
< asp:Panel ID = Panel2 runat = server >
< asp:UpdatePanel ID = UpdatePanel2 runat = 服务器 >
< ContentTemplate >
< asp:DropDownList ID = DropDownList2 runat = server AutoPostBack = True OnSelectedIndexChanged = DropDownList2_SelectedIndexChanged >
< asp:ListItem > 选择< / asp:ListItem >
< asp:ListItem > Panel1 < / asp:ListItem >
< / asp:DropDownList >
< / ContentTemplate >
< 触发器 >
< asp:AsyncPostBackTrigger ControlID = DropDownList2 / >
< /触发器 >
< / asp:UpdatePanel >
< asp:TextBox ID = TextBox2 runat = server > < / asp:TextBox >
< asp:按钮 ID = btnP2 runat = server 文本 = Panel2 OnClick = btnP2_Click / >
< / asp:Panel >
< / div >
< / form >
< / body >
< / html >
受保护 void DropDownList1_SelectedIndexChanged( object sender,EventArgs e)
{
if (DropDownList1。 SelectedValue.ToString()== Panel2)
{
Panel2。 Visible = true ;
Panel1.Visible = false ;
}
}
受保护 void DropDownList2_SelectedIndexChanged( object sender,EventArgs e)
{
if (DropDownList2.SelectedValue.ToString()== Panel1)
{
Panel2.Visible = 假跨度>;
Panel1.Visible = true ;
}
}
受保护 void btnP1_Click( object sender,EventArgs e)
{
Panel1.Visible = false ;
Panel2.Visible = true ;
}
受保护 void btnP2_Click( object sender,EventArgs e)
{
Panel1.Visible = true ;
Panel2.Visible = false ;
}
解决方案
hi itsureshuk,
给这个:EventName = SelectedIndexChanged
事件:
AsyncPostBackTrigger
所以,这样:
< asp:asyncpostbacktrigger controlid = DropDownList1 eventname = SelectedIndexChanged />
和asp中的一个:DropDownList2的AsyncPostBackTrigger
< asp:asyncpostbacktrigger controlid = DropDownList2 eventname = < span class =code-string> SelectedIndexChanged />
我希望这有帮助,
Hi Frnds,
Below code i have two Panel.Inside drop down change event i need to change panel change.but page also getting refresh how to do without refresh.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:Panel ID="Panel1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>Panel2</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" />
</Triggers>
</asp:UpdatePanel>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="btnP1" runat="server" Text="Panel1" OnClick="btnP1_Click" />
</asp:Panel>
<asp:Panel ID="Panel2" runat="server">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>Panel1</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList2" />
</Triggers>
</asp:UpdatePanel>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="btnP2" runat="server" Text="Panel2" OnClick="btnP2_Click" />
</asp:Panel>
</div>
</form>
</body>
</html>
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue.ToString() == "Panel2")
{
Panel2.Visible = true;
Panel1.Visible = false;
}
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList2.SelectedValue.ToString() == "Panel1")
{
Panel2.Visible = false;
Panel1.Visible = true;
}
}
protected void btnP1_Click(object sender, EventArgs e)
{
Panel1.Visible = false;
Panel2.Visible = true;
}
protected void btnP2_Click(object sender, EventArgs e)
{
Panel1.Visible = true;
Panel2.Visible = false;
}
解决方案
hi itsureshuk,
give this :EventName="SelectedIndexChanged"
in event :
AsyncPostBackTrigger
so, to be this :
<asp:asyncpostbacktrigger controlid="DropDownList1" eventname="SelectedIndexChanged" />
and one again in asp:AsyncPostBackTrigger for DropDownList2
<asp:asyncpostbacktrigger controlid="DropDownList2" eventname="SelectedIndexChanged" />
I hope this helps,
这篇关于在Asp .net中使用下拉列表和Panel可见问题更新Panel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文