2016-06-29 18 views
-1

私はアップデートパネル内でファイルアップロードを使用していますので、PostBackTriggerを追加してbtnsubmitを動作させてください。ポストバック後にdivを表示しない

<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コード

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">&times;</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">&times;</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> 
+1

あなたのdivコードは更新パネル内にあるべきです –

+0

更新パネルコードを投稿してください。 –

+0

Nazir Ullah更新パネル内 – Ayman

答えて

-1

代わりに以下を使用してみてください:

divfalse.Attributes.Add("style", "display:none;"); 
+0

divtrue.Visible = false;動作します。 –

関連する問題