[Solved] ASP.Net FileUpload control not working inside Bootstrap Model Popup

Last Reply 3 months ago By pandeyism

Posted 3 months ago

FileUpload control not working inside Bootstrap Model Popup

You are viewing reply posted by: pandeyism 3 months ago.
Posted 3 months ago

Hi IamAzhar,

Refer below sample.

HTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#MyPopup">
            Open Modal</button>
        <div id="MyPopup" class="modal fade" role="dialog">
            <div class="modal-dialog">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        x</button>
                    <h3>
                        Detail</h3>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="form-group">
                                <asp:FileUpload ID="idFileUpload" runat="server" />
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <asp:Button ID="btnSubmit" runat="server" Text="Save" CssClass="btn btn-success"
                        OnClick="btnSubmit_Click" />
                    <button class="btn btn-info" data-dismiss="modal" aria-hidden="true">
                        Close</button>
                </div>
            </div>
        </div>
    </div>
    </form>
</body>
</html>

Code

C#

protected void btnSubmit_Click(object sender, EventArgs e)
{
    ScriptManager.RegisterStartupScript(this, this.GetType(), " ", "alert('" + idFileUpload.PostedFile.FileName + "');", true);
}

VB.Net

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
    ScriptManager.RegisterStartupScript(Me, Me.GetType(), " ", "alert('" & idFileUpload.PostedFile.FileName & "');", True)
End Sub

Screenshot