Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

ModalPopupExtender + FileUpload + Show Image on Page

$
0
0

Hello, 

  I am trying to open a popup window on a button click "Upload" thru ModalPopupExtender. Below "Upload" btn I have an Image control to display the selected image.

In the popup window I have FileUpload. On click of FileUpload button, in code behind I want to show the image in the popup Image Control "showPanImg" & then when the user clicks "Set" btn of popup, I want to save the image to server & show in the form in Image control. I have "SEt" & "Cancel" btns in poup window. But once on Upload of FileUpload btns is clicked and control is gone to code behind, then the popup is not visible.

My Upload Btn & Image Control code :

<td><asp:LinkButton runat="server" id="panBtn"
                        CssClass="popup_a btn menu-green">Upload PAN<span class="glyphicon glyphicon-chevron-down"></span></asp:LinkButton></td><td><asp:Image runat="server" ID="panImg" BorderStyle="Ridge" BorderColor="Turquoise" Width="100px" Height="100px" /></td>

On clicking "Upload PAN" btn, a popup is opened using ModalExtender...

<ajaxToolkit:ModalPopupExtender ID="pan" runat="server"
            TargetControlID="panBtn" PopupControlID="view_PanImages_popup"
            RepositionMode="RepositionOnWindowResizeAndScroll" DropShadow="true"
            PopupDragHandleControlID="uploadPanImage"
            CancelControlID="cancelPan"
            BackgroundCssClass="modalBackground"></ajaxToolkit:ModalPopupExtender>   

The Panel of Popup :

<asp:Panel id="view_PanImages_popup" CssClass="modalPopup" runat="server" Width="450px" Height="270px"><asp:Label id="uploadPanImage" runat="server" CssClass="pop-title">Upload PAN Image</asp:Label><table class="table" style="width:100%;" ><tr><td><asp:FileUpload runat="server" ID="panUploader" /><asp:Button runat="server" ID="panUploadBtn" Text="Upload" OnClick="panUploadBtn_Click" /></td><td><asp:Image runat="server" ID="showPanImg" BorderStyle="Ridge" BorderColor="Turquoise" Width="100px" Height="100px" /><%--                    	    <div id="showimages" style="width:150px;height:100px;">No images found</div>--%></td></tr><tr><td colspan="2"><asp:Label ID="panUploadStatusLbl" Text="" runat="server" CssClass="greenText" ></asp:Label>  <%--CssClass="error"--%></td></tr></table><div class="one-row" style="text-align:right; margin-right:10px;"><asp:LinkButton ID="okPanImg" runat="server" PostBackUrl="#" CssClass="btn menu-blue"
                        Style="background-color: green;" OnClick="okPanImg_Click"><span class="glyphicon glyphicon-ok"></span> Set </asp:LinkButton>   <asp:LinkButton ID="cancelPan" runat="server" CssClass="btn cancel_button"  ><span class="glyphicon glyphicon-remove"></span> Cancel </asp:LinkButton>  </div></asp:Panel>

In Code-behind, On fileUpload btn :

        // Upload PAN Card Image
        protected void panUploadBtn_Click(object sender, EventArgs e)
        {
            if (panUploader.HasFile)
            {
                try
                {
                    string path = Server.MapPath("~/CRMImages/");
string mypath = "~/CRMImages/"; if (panUploader.PostedFile.ContentType == "image/jpeg") { if (panUploader.PostedFile.ContentLength < 102400) { string fileName = Path.GetFileName(panUploader.FileName); panUploader.SaveAs(Server.MapPath("~/CRMImages/") + fileName); //IN SET panImg.ImageUrl = mypath + fileName; // SHOW IN FORM IMAGE - THIS TO BE DONE IN SET CLICK showPanImg.ImageUrl = mypath + fileName; // SHOW THE IMAGE IN POUP panFileUrlTxt.Text = mypath + fileName; // Saves the path in a textbox } else { panUploadStatusLbl.CssClass = "redText"; panUploadStatusLbl.Text = "File has to be less than 100kb"; } } else { panUploadStatusLbl.CssClass = "redText"; panUploadStatusLbl.Text = "Only JPEG files are accepted"; } } catch (Exception ex) { panUploadStatusLbl.CssClass = "redText"; panUploadStatusLbl.Text = "File could not be uploaded. Error occured: " + ex.Message; } } }
        protected void okPanImg_Click(object sender, EventArgs e)
        {
// THIS IS NEVER FIRED, AS ONCE ABOVE EVENT IS FIRED, THE POPUP IS UNLOADED, SO NO CHANCE FOR THIS EVENT if (panFileUrlTxt.Text.Length > 0) { panImg.ImageUrl = panFileUrlTxt.Text; //File.Copy(panFileUrlTxt.Text, Server.MapPath("~/") + panFileUrlTxt.Text); } }


I just want to simply have my FileUpload control in popup & show the selected file in POPUP & once user is confirm, click "Set" btn in popup & show in form.  How to make the popup be shown even after FileUpload upload btn event is fired on server. Currently, on FileUpload upload btn (after code-behind) the popup is unloaded & have no chance to click "Set" or "Cancel" btns ??

Can you please help me out. Any help is highly appreciated.

Thanks


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>