I have a ajax file upload inside my update panel to upload the file immediately after the user selects a file to upload. During the file upload in btnVidUpload_Click I assign the file name to the hidden field which is also inside the update panel. Then when I click Submit Send_Click tries to get the value from the hidden field, but the hidden field is empty, why is the hidden field losing its value, cant it retain the value during post back or is there a way to store the value without using session. thanks
<asp:AsyncFileUpload ID="AFU_Video" OnUploadedComplete="btnVidUpload_Click"
runat="server" UploaderStyle="Traditional" ThrobberID="aajaxLoader" />
<asp:HiddenField ID="Hidd_VideoLoc" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:ImageButton ID="btn_Send" Text="Submit" runat="server" OnClick="Send_Click" />
The AsyncFileUpload internally uses an iFrame to render the FileUpload control.
That is the reason why it seems to lose it's value.
You need to use the Session in btnVidUpload_Click.
Own answer on a similar question: https://stackoverflow.com/a/8495986/284240
Related
I have page Searchbook.aspx which have 3 dropdowns and one repeater control which have button when i navigate to another page through that button to another page .when i click the back button of browser first page get default values instead of searched values. i want to restore the searched values.
You can switch on the history of the browser for update panel requests by setting the switch EnableHistory=true in the ScriptManager.
Here is a code sample that might help...
<asp:ScriptManager ID="scm" runat="server"
EnableHistory="true"
OnNavigate="scm_Navigate"
/>
<div>
<asp:Button ID="btnSubmit" runat="server" Text="Click Me!"
onclick="btnSubmit_Click" />
<asp:UpdatePanel ID="upl" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblTime" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
Here is the source: http://aspnetpodcast.com/CS11/blogs/asp.net_podcast/archive/2008/06/15/asp-net-podcast-show-116-using-the-history-functionality-with-the-asp-net-ajax-updatepanel-in-net-3-5-service-pack-1-beta-1.aspx
UPDATE
You can also use this method for adding a history point in browser.
http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.addhistorypoint(v=vs.100).aspx
Maybe this answer on SOF can also help...
https://stackoverflow.com/a/365746/217757
UPDATE 2
This blog post from Scott Gu sums it all...
http://weblogs.asp.net/scottgu/Tip_2F00_Trick_3A00_-Enabling-Back_2F00_Forward_2D00_Button-Support-for-ASP.NET-AJAX-UpdatePanel
If you want to restore the searched values on browser back button, then there are two ways to solve.
Keep the filter values selected by user in ViewState.
=> In this case always bind you data by implementing conditions which get from viewstate.
Or keep the values for filter data in query string.
=> In this case when user selected filter criteria put values in query string and bind data by putting condition with value fetched from URL query string.
Both above process can solve your purpose but the second one will be efficient and fast as putting values in Viewstate will slow down page.
Please let me know if I am not able to get you issue properly.
Update -
You can use Viewstate method as you are using update panel and using query string make page refresh.
Viewstate is same as using Session variable, please see below code.
Add value in viewstate
ViewState.Add("filter1", DropDownList1.SelectedValue);
Get value from viewstate
string getvalue = ViewState["filter1"].ToString();
So when after selecting filter criteria when click on submit button set value in viewstate and on page load get the same value and bind your control using those values.
I have following html in my aspx page
<asp:Textbox id="myTextField" runat="server" cssclass="mycssclass" data-control-id="<%= search.ClientID %>"></asp:textbox>
<asp:Button ID="search" runat="server" Text="Search" />
the problem is "<%= search.ClientID %>" render as it is in the aspx file. i need to render the client id of control.
Thy this :
And call
this.DataBind(); in page_Load
(notice change in <%#)
<asp:Textbox id="myTextField" runat="server" cssclass="mycssclass" data-control-id="<%# search.ClientID %>"></asp:textbox>
Another (more convenient solution) is to use html elements which are not server side :
<input type='text' id="myTextField" runat="server" class="mycssclass" data-control-id="<%= search.ClientID %>" />
and then get it via Request.Form[...] ( via name attribute)
If you want to know what the client ID will be, then search and read about the setting "ClientIDMode" - setting it to Static, for example, will set the client-side ID in the DOM equal to the server side ID that you set. Just make sure have only one instance of that Control on your page otherwise you have more than one control with that ID, and that won't fly. If that control will be in a repeater, item template or any other "repeating" control, then add an index counter for the loop to dynamically alter then ID slightly.
I have textbox in asp.net where i am writting Address.
On linkbutton below i wanted to direct it to goole map.
I have below textbox:
<asp:TextBox ID="txtJobAddress" runat="server" TextMode="MultiLine" Width="95%" Height="20px"
onBlur="javascript:saveChanges('JobAddress');"></asp:TextBox>
Linkbutton as below:
<a href="http://maps.google.com/maps?q=<%=txtJobAddress.Text%>" target="_blank">
<img src="images/gmap_button.gif" alt="Map" />
</a>
but when its getting directed through anchor tag, its not catching "q" parameter.
Its giving as:
https://www.google.com/maps/preview?q=
why its not taking value of:
<%=txtJobAddress.Text%>
Please help me , how can i attach textbox string here in
http://maps.google.com/maps?q=<%=txtJobAddress.Text%>
as below
http://maps.google.com/maps?q=NewYork
The <%=txtJobAddress.Text%> will be empty on page load. Presumably your saveChanges method prompts an ajax call to save the "JobAddress"? If this is the case then a full page postback won't occur, and therefore the <%=txtJobAddress.Text%> isn't populated with the updated value as this would occur on the server. You'll want to populate the query string value client side
e.g. in your blur event you could add a call to a javascript function that updates your link:
onBlur="javascript:saveChanges('JobAddress'); updateLink()"
in your updateLink function you would update the link query string value
I have a csv importroutine which imports my CSV values into Sitecore. After this proces is done i want to show the errors in an asp:literal. This is not working, and I think this is because i need an updatepanel for this in order to be able to update text after the first postback (the csv upload / import).
I made this:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
and coded this:
string melding = string.Format("Er zijn {0} objecten geïmporteerd.{1}", nrOfItemsImported, errors);
ViewState["Melding"] = melding;
And i have a button. On the onclick of this button I have:
Literal literal = new Literal();
literal.Text = (string)ViewState["Melding"];
literal.ID = DateTime.Now.Ticks.ToString();
UpdatePanel1.ContentTemplateContainer.Controls.Add(literal);
PlaceHolder1.Controls.Add(literal);
When i now press the button i want to update the panel so that it will show my Literal with the errormsg on it. This however isn't happening. How can this be? I'm guessing it has something to do with my viewstate, i don't see keys on the viewstate after I press the button...
#Update:
I found the problem. I was storing information in a session, however the data for the key i was storing the information in was too large. This made the Session key empty. I was posting an empty string into my literal and therefore no information was shown. I am now looking for a better way to store my data and make it show in my updatepanel. I have tried Viewstate / Session / Cookies and none of it would work the way i wanted. When I am using a viewstate I am not able to store information. The viewstate (debugmode) shows count 0 and 0 keys ... Hope someone knows a good way to make sure that my errorstring (476kb) gets stored somewhere where i can easily post it to my updatepanel's literal.
If you are using a FileUpload control, then you cannot use the UpdatePanel to asynchronously update the panel. The file upload is a synchronous event, so you'll need to update the Literal control on the page after the upload completed during the next Page_Load event.
In your code, have you tried UpdatePanel1.Update();? Even though you have added a control, you still will need to "trigger" the update to the update panel.
See here for a possible similar issue: StackOverflow
I tried this code and on click of button I am able to get the literal text on web page. Can you provide with some more details .
How can update a input hidden inside an UpdatePanel on an AsyncPostBack?
The user click a button outside the panel. The method associated with click event update the value of the input (it has runat="server" property).
I can't update the value of this input.
I need to store a value to use in the following postback. Maybe I can use session to store this value.
Any advice?
Thank you!
Because its a postback, you might have to perform a check in the post back event and perform the update. If not, you might have to override an earlier event. See http://msdn.microsoft.com/en-us/library/dct97kc3.aspx
If you are needing to have the update panel (and its contents) updated based on the user clicking on a button which is not in the update panel, add a section to the update panel like the following:
<asp:Button ID="btnOK" runat="server"/>
<asp:UpdatePanel ID="pnlMyPanel" runat="server">
<ContentTemplate>
<!-- Content to get updated -->
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnOK" />
</Triggers>
</asp:UpdatePanel>
The triggers section in the above example tells the update panel to update if the button is clicked.
You might want to try an <asp:HiddenField> rather than an <input type='hidden' runat='server'>. I think the asp.net version is more post-back aware.
No way. The only way to update an input is to do a complete post. It's better to use the object Session.