我在更新面板中使用文件上传,所以我将postBackTrigger添加到btnsubmit以使其正常工作。
<asp:PostBackTrigger ControlID="btnsubmit" />
问题是divtrue
或divfalse
应该在页面刷新后隐藏。
以下代码用于隐藏div但在添加PostBackTrigger后它不会隐藏。
protected void Page_Load(object sender, EventArgs e)
{
Page.Form.Attributes.Add("enctype", "multipart/form-data");
if (!IsPostBack)
{
gridItem.DataSource = i.GetItems();
gridItem.DataBind();
}
divfalse.Visible = false;
divtrue.Visible = false;
}
btnsubmit Code
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>
答案 0 :(得分:-1)
请尝试使用以下内容:
divfalse.Attributes.Add("style", "display:none;");