C# 回发后隐藏div
我在更新面板中使用文件上载,所以我将PostBackTrigger添加到btnsubmit以使其工作C# 回发后隐藏div,c#,asp.net,C#,Asp.net,我在更新面板中使用文件上载,所以我将PostBackTrigger添加到btnsubmit以使其工作 <asp:PostBackTrigger ControlID="btnsubmit" /> b提交代码 string imgPath; protected void btnsubmit_Click(object sender, EventArgs e) { try { if (imgup.HasFile) {
<asp:PostBackTrigger ControlID="btnsubmit" />
b提交代码
string imgPath;
protected void btnsubmit_Click(object sender, EventArgs e)
{
try
{
if (imgup.HasFile)
{
string imgName = imgup.FileName.ToString();
imgup.SaveAs(Server.MapPath("Images/") + imgName);
imgPath = "Images/" + imgName;
}
string msg=i.AddItem(txtitemcode.Text,imgPath,DateTime.Now.ToShortDateString());
if (msg == "true")
{
gridItem.DataSource = i.GetItems();
gridItem.DataBind();
MultiView1.ActiveViewIndex = 0;
divtrue.Visible = true;
}
else
{
MultiView1.ActiveViewIndex = 0;
divfalse.Visible = true;
}
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
}
}
更新面板
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">
<div class="alert alert-success" runat="server" id="divtrue">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Success!</strong>
<asp:Label ID="lbltrue" runat="server" Text="Item added successfully."></asp:Label>
</div>
<div class="alert alert-danger" runat="server" id="divfalse">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Error!</strong>
<asp:Label ID="lblfalse" runat="server" Text="Item not aadded please try again."></asp:Label>
</div>
</asp:View>
<asp:View ID="View2" runat="server">
<%--Adding form %>
<div class="btn-group">
<asp:Button ID="btnsubmit" runat="server" OnClick="btnsubmit_Click" class="btn btn-primary" Text="Submit" Width="100px" ValidationGroup="g1" />
</div>
</asp:View>
</asp:MultiView>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnsubmit" />
</Triggers>
</asp:UpdatePanel>
成功强>
错误强>
尝试使用以下方法:
divfalse.Attributes.Add("style", "display:none;");
你的div代码应该在更新面板内发布你的更新面板代码。Nazir Ullah在更新面板内将UpdateMode设置为
始终
Akash Amin无任何更改
divfalse.Attributes.Add("style", "display:none;");