I am working on an Asp.net project and we have some interfaces to load corresponding reports.
My html code is as follows:
<form id="form1" runat="server">
<div>
/*----html code for selecting parameters----*/
<asp:Button Text="Submit" AutoPostBack="False" CssClass="btn btn-primary" runat="server" ID="btnSubmit" OnClientClick="javascript:return Validate()" OnClick="btnSubmit_Click" />
/*----Button to check validity and load report----*/
</div>
/*----Some html codes----*/
<CR:CrystalReportViewer ID="CRViewer" runat="server" AutoDataBind="true" EnableParameterPrompt="False" ReuseParameterValuesOnRefresh="True" ToolPanelView="None" EnableDatabaseLogonPrompt="False" HasCrystalLogo="False" HasToggleGroupTreeButton="False" HasToggleParameterPanelButton="False" HasDrilldownTabs="False" HasDrillUpButton="False" HasRefreshButton="True" HasPageNavigationButtons="True" HasPrintButton="True" DisplayToolbar="True" />
/*----this is where report get loaded----*/
</form>
after selecting parameters and clicking submit button, the report gets loaded, but the page gets reloaded and all parameters get reset.
How do I prevent the parameters from getting reset?
To prevent the whole page from reloading you need to use a updatepanel to do partial postback.
The example would look like this
<asp:UpdatePanel ID="UpdatePanel" runat="server>
<ContentTemplate>
<CR:CrystalReportViewer ID="CRViewer" runat="server" AutoDataBind="true" EnableParameterPrompt="False" ReuseParameterValuesOnRefresh="True" ToolPanelView="None" EnableDatabaseLogonPrompt="False" HasCrystalLogo="False" HasToggleGroupTreeButton="False" HasToggleParameterPanelButton="False" HasDrilldownTabs="False" HasDrillUpButton="False" HasRefreshButton="True" HasPageNavigationButtons="True" HasPrintButton="True" DisplayToolbar="True" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" />
</Triggers>
</asp:UpdatePanel>
Make the button the trigger for the updatepanel meaning if you press the button only the part inside the updatepanel will reload so you won't lose any values
Related
I have a html input control within a asp:UpdatePanel and I have its associated upload button specified within a asp:PostBackTrigger tag. Here is the aspx code:
<asp:UpdatePanel ID="upGallery" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<portal:ModuleTitleControl id="Title1" runat="server" />
<portal:OuterBodyPanel ID="pnlOuterBody" runat="server">
<portal:InnerBodyPanel ID="pnlInnerBody" runat="server" CssClass="modulecontent">
<div id="Uploader" runat="server">
<h2>Upload a docx file to be translated.</h2>
<input id="input_FileUpload" runat="server" type="file" />
<asp:Button ID="button_UploadFile" runat="server" OnClick="button_UploadFile_Click" Text="Upload" />
</div>
</portal:InnerBodyPanel>
</portal:OuterBodyPanel>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="button_UploadFile" />
</Triggers>
</asp:UpdatePanel>
Here is the code behind to retrieve the value of the input control "input_FileUpload":
string filename = input_FileUpload.Value;
filename is always empty when I step through the code.
What am I doing wrong?
The FileUpload control has known problems with the UpdatePanel. Check out this prior discussion: FileUpload control inside an UpdatePanel without refreshing the whole page?
I am using a UpdatePanel, and my submit button is one of the triggers along with the clear button. But the problem is I have a FileUpload Control in the div. This is a modal popup, so it displays a form for a user to upload a little note. When I try to upload a file with AsyncPostBackTrigger it does nothing (which I have read about). My question is how do I not use the PostBackTrigger because I want to use the asyncpostbacktrigger because if an error occurs, then the Modal popup closes and the user doesnt know if the file was uploaded or not. What can I do?
Code:
<asp:Panel ID="addnotepanel" runat="server" style="/*display:none;*/" CssClass="addnotepanel">
<asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ClrBtn" />
<asp:PostBackTrigger ControlID="SubmitBtn" />
</Triggers>
</asp:UpdatePanel>
File:
<br />
<asp:Label ID="ErrorLabel" runat="server" Visible="False"></asp:Label>
<br />
<asp:Button ID="Submitbtn" runat="server" Text="Submit"
onclick="Submitbtn_Click" />
<asp:Button ID="CnlBtn" runat="server" Text="Cancel" onclick="CnlBtn_Click" />
<asp:Button ID="ClrBtn" runat="server" onclick="ClrBtn_Click"
Text="Clear" />
</div></asp:Panel>
keep SubmitBtn as a PostBackTrigger but dont set it as the "OkControlID" of the modalpopupextender.
in the Submitbtn_Click server side sub, call yourModalpopupextenderID.hide() if the upload is completed so the Modal pop up closes only if there is no error.
You could use a AsyncFileUpload from the AjaxControlToolkit
Here, as an exemple some code to show how to use it :
<AjaxControlToolkit:AsyncFileUpload ID="AttachementsFileUpload"
runat="server"
OnUploadedComplete="AttachementsFileUpload_UploadedComplete"
OnClientUploadComplete="uploadComplete" />
<script type="text/javascript">
var UpdateAttachementsGridViewButton = '<%= UpdateAttachementsGridViewButton.ClientID %>';
function uploadComplete(sender, args) {
$get(UpdateAttachementsGridViewButton).click();
}
</script>
As you see, when the upload is complete, I use Javascript to trigger an click on an hidden button. Meanwhile I retrieve the file in the AttachementsFileUpload_UploadedComplete using something like this:
Dim AttachementsFileUpload As AjaxControlToolkit.AsyncFileUpload = AnnouncementFormView.FindControl("AttachementsFileUpload")
Attachements.add(e.filename, AttachementsFileUpload.FileBytes)
It's how I used it in my situation, but you will find plenty of examples on how it work
Im trying tp upload more than one image, and when each one I upload I will show it in a repeater, but in the code behind the FileUpload1.HasFile is always False , this is a piece of my code :
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Repeater ID="rpUploadedImages" runat="server">
<ItemTemplate>
<img src='../Images/<%# DataBinder.Eval(Container.DataItem, "ImagePath")%>'/><br />
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnupload" EventName="click" />
</Triggers>
</asp:UpdatePanel>
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<asp:Button ID="btnupload" runat="server" Text="Upload" onclick="btnupload_Click" />
The FileUpload control does not work with UpdatePanel, you will need to do a full post back to get the file on the server... Now there are a lot of tricks to make it ajaxy...
http://geekswithblogs.net/ranganh/archive/2008/04/01/file-upload-in-updatepanel-asp.net-ajax.aspx
Another tricky way is to create iframe with fileupload + submit button(or some trigger) inside your main form. iframe will postback with no effect to main page.
I have a button is inside a another table(s) inside the update panel.
<Update panel>
<ContentTemplate>
<table>
<table>
<Button>
<table>
<table>
</ContentTemplate>
</Update panel>
I would like to add a button to Update panel's trigger.
But am getting an err says "Update panel can not find the button which trigger it".
I am getting "Sys.Webforms.PageRequestmanagerParseErrorException: This message recieved from manager could not be parsed. Common cause for this error are when response is modified by response.write"
Please help!
PostBackTrigger example:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btn1" runat="server" Text="Button 1-Partial Postback" />
<asp:Button ID="btn2" runat="server" Text="Button 2-Full Postback" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btn2" />
</Triggers>
</asp:UpdatePanel>
I have a page and it has a button and a user control.
I want to refresh the user control without refreshing the page.
I know I cannot do it otherwise so what I did is wrapped my user control inside the Update Panel.
<asp:TextBox ID="txtName" runat="server"></asp:TextBox><br />
<asp:Button ID="btnAdd" runat="server" Text="Add name to list" OnClick="btnAdd_Click" /><br /><br />
<asp:UpdatePanel ID="upShowNames" runat="server">
<ContentTemplate>
<uc1:ShowNames ID="ucShowNames" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAdd" />
</Triggers>
</asp:UpdatePanel>
But I still the control won't refresh.
I also tried calling the update panels. The Update() method by changing its UpdateMode to Conditional but that does not work either...
Does anyone know how can I do it?
Please change these 2 things
<asp:UpdatePanel ID="upShowNames" runat="server" UpdateMode="Conditional">
<asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click"/>
You missed the EventName on the postback trigger, once you add that, it should work :-)