I see this question asked frequently and I have done extensive experimentation to try to get this to work. However everyone else's examples and answers have so far failed me. I am bemused. Here is the situation:
AsyncFileUpload is NOT in an UpdatePanel
Image and Label to be updated are in an UpdatePanel
Update should occur after the upload completes
The upload is indeed saving the file as expected. My problem is regarding getting the page to update after that happens. The file being uploaded is an image, and I would like that image to update. I am aware of some problems with images not updating on the client if you reuse filenames, but I am also printing it to a label just to be sure. I am certain the UpdatePanel I am targeting is not updating.
I have tried the following approaches:
Using the server side method to manually update a conditional UpdatePanel - this fails because the file upload is done in a frame. Sniffing the returned HTML shows that the correct HTML is actually sent back after the post, but of course to the wrong frame.
Using the client side method to trigger a javascript postback to my UpdatePanel. This does not work and I cannot tell why.
Using the client side method to trigger a javascript button click inside the UpdatePanel. Again, nothing happens and I don't know why.
Setting the UpdatePanel's trigger up so that it points directly at the AsyncFileUpload. No joy, but I knew that would be a long shot, keeping in mind the hidden frame.
Moving the AsyncFileUpload into the UpdatePanel and trying some variety of the above. When I do this, I lose all handle of the file being posted to the server and I cannot save the file in the first place.
Normally when I get this kind of error, where all the tutorials appear to be wrong, it turns out that my error is because I didn't set an ID on a control somewhere and it somehow mattered. I can't even see that in this case. Here is some code.
<fieldset class="pj_Pics">
<ul>
<li>
<label>Picture 1</label>
<asp:UpdatePanel ID="ajax_Pic1" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:Image ID="img_Pic1" runat="server" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
<div style="position:relative;">
<div class="photoChooser">
<ajaxToolkit:AsyncFileUpload ID="fu_Pic1" runat="server" CssClass="pj_PicChoose" Width="84px" OnClientUploadComplete="picPost1" OnUploadedComplete="fu_PictureFile_UploadedComplete" ThrobberID="throb1" />
<span><asp:Literal runat="server" Text="click to change"></asp:Literal></span>
<asp:Image ID="throb1" runat="server" ImageUrl="~/images/throbber.gif" AlternateText="uploading image" />
</div>
</div>
</li>
</ul>
</fieldset>
protected void fu_PictureFile_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
bla bla bla;
// and update the image
img.ImageUrl = "~/" + webfolder + imageFileName;
thing.Text = img.ImageUrl;
}
function picPost1(sender, args) {
document.getElementById('<%# Button1.ClientID %>').click();
}
Any help greatly appreciated. There is obviously a ScriptManager on the page and the code I've shown is just the last thing I have attempted. Let me know if there is anything else you need to see.
Thank you!
I happen to face the same situation today, and this is how I solved it.
According to this LINK, there's no Postback is happening or even a ViewState since its Asynchronous FileUpload.
So in OnUploadedComplete I test file type and size before executing the SaveAs() in codebehind, then I test the same in OnClientUploadComplete to display messages and carry on the rest of the work like setting Images URL. Hope this helps.
Related
I am facing an issue that is really hard to debug. I have a JSP page that has some form elements on it that submit to a Struts2 action. I also have a XML form validation file to perform some validation on the submitted fields. The file has the naming convention 'actionName-validation.xml'
This works fine, but when I add a drop down box, outside of the form, the validation now fails. Instead it redirects to a blank page and my breakpoint in my action class is not hit.
Is there a way to turn on some kind of debugging or logging for the validation? Why would adding a tag outside of a form cause this to happen?
Here is the code on the JSP page:
<s:select id="dataSource" name="selectedDataSource" theme="simple" listValue="top"
headerKey="" headerValue="Choose Data" list="dataSources" size="1" />
<div id="forms">
<s:form method="post" action="MyAction" theme="simple">
<p>
<label class="input" for="name"
<span style="color:red;">*</span>
<span>Name</span><br>
<s:textfield theme="simple" name="name" maxlength="11" size="11" />
<br>
<s:fielderror theme="plain"><s:param value="'name'" /</s:fielderror></label>
</p>
<s:submit value="Create New" theme="simple" cssStyle="display: block; clear: left;"/>
</s:form>
</div>
If I remove the <s:select> tag, it works.
Any help would be greatly appreciated it.
EDIT2: I found the problem. I needed a get method for the list that is used to populate the select drop down inside the action that the form submits to.
I had one for the action that initially is called for the page, but when the validation fails and it re-loads that page from the form action class, it tries to re-populate the select drop down and needs a getter there. I feel silly for not finding that sooner. Would be nice if there were some type of logging or messaging of these types of issues.
thanks.
The error you are encountering is not a validation error (handled by the Validation Interceptor), but an error occurred when setting the parameters (raised by the Parameters Interceptor) and for which the Conversion Error Interceptor added a fieldError, which you are not seeing because
your INPUT result lands on a blank page and
you are using theme="simple" on the textfield, which forces you to add <s:fielderror fieldName="dataSource" /> to show it (or <s:fielderror /> to show them all).
Read how the INPUT result works, set your page as the INPUT page, print the errors, then you will discover the problem, that is most likely related to the fact that you've not specified a listKey attribute in your select, that is sending the description instead of the code of the datasource to selectedDataSource, which is probably an Integer.
I found the problem. I needed a get method for the list that is used to populate the select drop down inside the action that the form submits to.
I had one for the action that initially is called for the page, but when the validation fails and it re-loads that page from the form action class, it tries to re-populate the select drop down and needs a getter there. I feel silly for not finding that sooner. Would be nice if there were some type of logging or messaging of these types of issues.
The Ajax accordion on my page isn't functioning at all. It displays fine on the page, but I can't seem to expand/collapse the panes when I click on their Headers.
Here's my code (just the HTML portion as I'm not aware of any code behind that is needed):
<aj:Accordion runat="server" ID="acMain" SelectedIndex="0"
FadeTransitions="true"
TransitionDuration="400"
FramesPerSecond="40" RequireOpenedPane="false" TabIndex="0"
SuppressHeaderPostbacks="true" HeaderCssClass="acHeader"
HeaderSelectedCssClass="acHeaderSelected">
<Panes>
<aj:AccordionPane runat="server" ID="Panel1">
<Header>
...
</Header>
<Content>
...
</Content>
</aj:AccordionPane>
<aj:AccordionPane runat="server" ID="Panel2">
<Header>
...
</Header>
<Content>
...
</Content>
</aj:AccordionPane>
</Panes>
</aj:Accordion>
I've checked the official page for the Accordion as well as a number of blogs on the subject (all of which seem to be a copy of the official page with the author's own wording) and according to all of this, I can't see that I've done anything wrong or missed anything out.
Matter of fact, I've checked an Accordion my boss made a while back and my code's basically the same as his (only panel content is different) and he has no code-behind either, so I'm really lost here.
Any help will be greatly appreciated
EDIT
After adapting my code according to a sample on asp.net, I've managed to collapse the first pane (SelectedIndex 0), but the other one won't expand :/
So I copied the accordion code from the asp.net how to page and put my content into the panes, still had no effect.
As it turns out, there was a rogue </div> tag in my content that was wrecking the accordion so I recommend that anyone having any similar problems checks their content very thoroughly.
Also, it's worth noting here that as this particular sample worked for me and because I'm telling you to use it if you're having trouble, it's author did leave an incorrectly closed </p> tag that might cause problems with your accordion during testing, so watch out for that.
This is an elementary problem (I think), and I am embarrassed to ask it here. It may have been answered already, but I could not find it my searches.
In its simplest form, there are two check-boxes, and each CheckBox has a control (e.g, TextBox or DropDownList) associated with it. When the checked state of a CheckBox changes, the associated control must be enabled or disabled.
JavaScript function:
<script type="text/javascript:>
function enable(bValue, control)
{
document.getElementByID(control).Enabled = bValue;
}
</script>
I'd call this function as an event procedure, e.g, enable(this.Checked, "expJob") and enable(this.Checked, "itemJob"), in the HTML below:
<body>
Billable? <asp:CheckBox ID="expBillable" runat="server" Checked="false" OnCheckedChanged="enable(this.Checked, "expJob");" />
to <asp:DropDownList ID="expJob" runat="server" Enabled="true" />
<br /><br />
Billable? <asp:CheckBox ID="itemBillable" runat="server" Checked="false" OnCheckedChanged="enable(this.Checked, "itemJob");" />
to <asp:DropDownList ID="itemJob" runat="server" Enabled="true" />
The problem is that, because of the use of quotes, I am unable to specify the "expJob" parameter in the HTML. Even the use of single quotes does not work.
So the question: Will this approach work? What is the proper syntax?
What is the best way to write and use a function such as this? I am sure such function use will be required when having to iterate over the rows in a grid.
Interestingly, all the questions/answers I have seen use a control's disabled attribute. I am only able to use the Enabled attribute. Can someone explain why, and what the difference is?
You have to use the single quotes ('itemJob')
I think OnCheckChanged is a server event. Asp.net needs a handler in the code behind when you want to use this. Thats why you are getting an error. Find the correct client side event when you want to fire a client side event. Take care of firing postbacks, but default for checkbox is "no auto postback" anyway.
Please be aware that javascript is case sensitive so
document.getElementById is good,
document.getElementByID is bad (note the ID in caps is bad)
I really need some help with this. I need to, using a RadWindow control, pop up a modal window containing a dynamically populated CheckBoxList based on user selection on dropdownlist changed. Please help with any sample or information to help me achieve this.
<telerik:RadWindow ID="UserListDialog" runat="server" Title="Editing record" Width="250" Height="536" VisibleOnPageLoad="false" Modal=true Behaviors="Minimize, Move, Resize,Maximize" Left="580" Top="-8" EnableShadow="true">
<ContentTemplate>
<div style="text-align: center;">
LIST OF STUFF TO DISPLAY
</div>
</ContentTemplate>
</telerik:RadWindow>
When using ContentTemplate, RadWindow behaves and can be used just like any other standard INamingConatiner.
For more details, check the help article and the demo on the subject.
I have an update panel on an .aspx page. Within this aspx page I have a few ascx controls. One of the controls has my link button. When that button is pressed I'd expect to get the results I intend to get, but I expect to not see a page flicker or see the page postback. It does both. After I change some search information and click the link button again the page does an async postback (which is what I expected on the first click). After running this sequence through fiddler I see that the first time I click the button I am missing some information that is included in all subsequent requests.
ctl00$ScriptManager1=ctl00$cplContents$updatePanelOrderSearch|ctl00$cplContents$ucOrderSearchControl$btnRange&EVENTTARGET=ctl00%24cplContents%24ucOrderSearchControl%24btnRange&.....
Above is what I get on clicks 2, 3, etc.. This is not in the request when I click on the link button the very first time. Im wondering if this is why I am get a full, non async postback the first time.
Any help would be appreciated. My update panel code is below.
<asp:UpdatePanel ID="updatePanelOrderSearch" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
<ContentTemplate>
<uc:control1 "this control has the link button" />
<hr />
<div id="SearchResults">
<div id="SearchResultsMessage">
<asp:Literal ID="lblMessage" Text="No orders found" Visible="false" runat="server" />
</div>
<uc:contorl 2 />
</div>
<uc: control3 />
</ContentTemplate>
</asp:UpdatePanel>
Thanks
this was an issue from months ago and we wound up not using this solution