I have a button on a .aspx page which opens the popup to upload images of selected item.
ListEdit.aspx
<asp:Button ID="btnListingImageUpload" runat="server" Text="Upload Images"
OnClientClick="basicPopup()"/>
Javascript:
function basicPopup() {
var QuoteId = document.getElementById('<%= hdnQuoteIDForListing.ClientID%>').value;
var IsPrep = document.getElementById('<%= hdnIsPrep.ClientID%>').value;
alert(IsPrep);
popupWindow = window.showModalDialog('ListingImageUpload.aspx?QuoteID=' + QuoteId + '&IsPrep=' + IsPrep, 'popUpWindow', 'height=400,width=600,left=200,top=250,resizable=0');
return false;
}
AjaxFileUpload Control on Popup Page:
<cc1:AjaxFileUpload ID="AjaxFileUpload2" ThrobberID="myThrobber" ContextKeys="fred" AllowedFileTypes="jpg,jpeg" MaximumNumberOfFiles="10" runat="server" OnUploadComplete="AjaxFileUpload1_UploadComplete1"
OnClientUploadComplete="onClientUploadCompleteFront" />
When i click on button it opens the page as popup containing AJAXFileUpload control and querystring in popup page. When i click on 'Upload' button of popup page containing AjaxFileUpload control it gives following error:
JavaScript runtime error: Sys.ArgumentException: Cannot deserialize. The data does not correspond to valid JSON.
Parameter name: data
But, when is use session instead of querystring it works fine!
I have googled and found this link but i am not able to resolve it. I have AJAXControlToolKit.dll (only)in bin folder and not the source files and other binaries.
NOTE: Please suggest solution using querystring only. Reason is, multiple instances of this popup will open at time. So, cant use Session variables.
Help Appreciated!
You can decompile de .dll with some App like Telerik, and then apply changes on the code and recompile.
This is a known issue, when AjaxFileUpload post back it takes your page URL and appends onto the end of it it's own.query strings (contextkey and guid). This works fine if your page URL doesn't already contain any query strings but
if it does then you end up with a URL that contains two question marks which will corrupt your final query string value and this in turn stops the upload from working.
Check this Known Issue
Related
Environment: Microsoft Visual Studio 2019 Community, ASP.NET v4.8 web application project using VB.NET
Problem: I have an asp imagebutton which is used to indicate a status by changing the image each time it is clicked (red-amber-green-red). This is done using javascript:
btn.src = newImage;
This works fine. The imageurl is accessed using src in the html but the image is initially set in the code behind databind by setting the imagebutton.imageurl:
btn.ImageUrl = initialImage
On a postback (a save) I want to find the status by looking at the current imageurl.
Dim btn As ImageButton = CType(mainGrid.Rows(i).FindControl("btn"), ImageButton))
someval = btn.imageurl
The problem is that imageurl shows the value initially set, not the changed value. This weirdness seems to point to a bug in my code somewhere as obviously the imagebutton variable in the save code behind knows nothing about the imagebutton variable in the databind code behind.
Can someone confirm that imageurl in the postback should in fact match the changed src in the html?
Edit: I should say that I don't want to use server-side processing each time they click the imagebutton. I can make this work using a command argument BUT that leads to a database write every time they click. There are a dozen or so buttons on each row so I think that would be pretty slow in production.
The answer, provided by Albert D. Kallal, is that imagebuttons don't pass any changed attributes back to the code behind. Possible solutions are to 1) use an update panel, 2) change a paired hidden field at the same time (of a type that does pass the change back) or 3) use ajax to update the db after the change. I used option 3.
I am trying to upload image files using html editor extender. Everything works fine so far and I am able to save the file on ImageUploadComplete event. But I am not sure how to raise the error to UI and alert user if the image upload fails for some reason.
Your help would be very much appreciated. Thanks!
Update: We use MS enterprise library for exception handling. In normal postback errors, the exception gets logged first and would get redirected to the custom error page. The issues with using HTMLEditorExtender are:
redirect on error is NOT working
fileupload control is showing wrong upload status - "Uploaded" even in case of failures.
Public Sub HTMLEditor_ImageUploadComplete(sender As Object,
e As AjaxControlToolkit.AjaxFileUploadEventArgs)
Handles HTMLEditor.ImageUploadComplete
HTMLEditor.AjaxFileUpload.SaveAs("D:\Uploads\" + Path.GetFileName(e.FileName))
End Sub
Since this is a server-side control you should be able to report errors like you would server-side for anything else (i.e. ASP.NET Label control with red forecolor and invisible until an error occurs), like this:
<asp:Label id="ErrorLabel" runat="server" ForeColor="Red" Visible="False"/>
Then on the method referenced in your OnImageUploadComplete attribute of the extender control you can direct error information to this error label control.
You can simply throw an exception and it will show as failed upload in the AjaxFileUpload box used by the HtmlEditorExtender.
If you want to handle the error yourself, you would either need to use the OnClientUploadError client side event of the AjaxFileUpload or download the AjaxControlToolkit source code and edit it to work as you need.
If your environment is unable to respond with and error HTTP Status then you can manually respond using Context.Response.Write() and write the appropriate JSON that the AjaxFileUpload expects. And then handle its client side events accordingly.
I have an html page that has a link to an external javascript file namely external.js as follows
<script type =" text/javascript" src="external.js"></script>
The page includes an <asp:HiddenField> defined as Hidden1.
In my external .js file there is a function passData() which basically populates Hidden1 with some values. The way I do it is as follows.
On HTML
<script> passData("<%=Hidden1.ClientID%>") </script> then in external.js:
function passData(hiddenFieldID)
{
document.getElementByID(hiddenFieldID).Value = "Value";
}
What I have been trying for some while now is to get the value of Hidden1 from my code behind in vb.net by using:
Dim str = Hidden1.value
However, with no luck. I have noticed that I should perform some sort of postback so that the value can be taken. However, what I am thinking of is that how on my html page the value of Hidden1 is showing when I use alert and at the same time I am not able to retrieve it on page_load in my .aspx unless I perform a postback. In my application I am really eager to get it working without having the need to add a button to initialize postbacks. I need to get Hidden1 value in my .aspx code-behind page in order to store it in a database. Any suggestions or ideas ?
I know my issue is very common and similar types has been asked many times over here, but my problem is somewhat different. I am working on ASP.Net 4.0 web application where on my required page i have ajax toolkit 4 calendar control, toolkitscript manager and few asp controls. Now from that pop up i am doing a save operation on button click. What i want is to close popup window after successful save. Problem is not in saving but after saving , automatically closing the popup screen. I have tried the following ways:
RegisterStartUpScriptBlock(this.GetType,"closeForm","return window.close();") and all other required params
ClientScript.RegisterStartUpScript()--- alongwith params and with both return window.close(); and window.close() also with self.close();
Also i have under the title tag...
I think i have tried all the ways , i can. I feel i am lost. Please help me out....
if your using a script manager on the page...
first create a function to close the calendar in js in your html...
function closeCalendar(){
....
}
then on the codebehind use this to call that js function
string script = string.Format(#"closeCalendar()");
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), UniqueID, script, true);
If the popup you mean is the AJAX Toolkit Modal Popup, you can just call popup.Hide(); in codebehind.
If it is a browser window, did you try to remove the return part from your code?
Note that windows.close() will not work unless the popup is opened via window.open();
Also, did you try to just put the script tag inside PlaceHolder control that is hidden (server-side Visible=false) by default and only shown when you need?
I have a page on my site on which users have to fill out details before they can download a document. The user details section is on the first view in a MultiView control.
After filling out their details I'd like the user to click a button which will show them a file download prompt (I've done this successfully with an ashx handler) then redirect them to the second view page of the MultiView which will say "thank you for downloading" or something like that.
I've tried the usual Response.Redirect("~/DownloadHandler.ashx"); within the button click event handler, but obviously this prevents the page completing the postback and showing the last page of the MultiView.
Is there a way around this, or should I just change my UI to accommodate this?
EDIT:
I've concluded that it's better to just provide a hyperlink to the document (on my confirmation page, and change the wording accordingly) as this provides a consistent user experience independent of the browser they're using.
Go ahead and take them to the second view of the MultiView. Add a javascript method that will download the document, and trigger it from your codebehind.1 E.g.,
In your page:
<script>
function downloadFile(url) {
window.location = url;
//you could also try window.open(url, 'Download')
}
</script>
In your code behind:
script = string.Format("downloadFile('{0}');", "DownloadHandler.ashx");
Page.ClientScriptManager.RegisterStartupScript(typeof(Page), "download", script, true);
You could also add a delay (using setTimeout) before the file is downloaded.
More info:
Initiating a file download that works well, even in IE?