changing the PostBackUrl in ASP.net after a file download - asp.net

I have a ASP.net which allows users to select a number of inputs and dropdown lists to filter the report and to download an Excel report after pressing a button on that same form.
The page can be used mulitple times, by changing the inputs and pressing the download
button each time.
The button should be posting back to the hidden IFRAME to a separate webpage, but I am
unable to change the target for the form on the fly as needed.
<form runat="server" method="post">
<asp:Button runat="server" id="DownloadToExcel" TabIndex="-1" Text="Download To Excel" UseSubmitBehavior="False" PostBackUrl="report.aspx" />
</form>
<iframe style="hide" id="output" src=""></iframe>
Additonally, when I download the file when pressing the "DownloadToExcel" button, the file downlodads as expected. However, any additional postbacks including updating the screen are posting back to report.aspx and not filter.aspx.
How do I correct the postback so it only postbacks once to download the file, and then change it back to the original page so the screen can continue to be used to filter and download a second report.
This may also eliminate the need of the IFRAME as well.

I solve the problem my adding PostBackURLs to all the submit buttons directly.
One for the Excel download that goes to report.aspx and the other for the postback on the page for filter.aspx.
It appears that if the postback is changed, in this case to report.aspx, it reuses the pathname for any subsequent postbacks, unless defined explicity, for each time you wish to postback.

Related

How to redirect to another page with using a function on that page with asp link

I am new to asp.net. So just learning everything step by step.
I have created a web project with the template.
On Page one, I have a button and a textbox with no action defined yet.
On Page two I have a button and a textbox and I also have db connections works from the button.
What I want to do is, if user writes something and click button on first page, I want to go page 2 and acts as clicked button.
I want to run some action on page two with parameter from page on.
I think this is possible with redireciton mechanism
I will post the code here. can anyone help me . I may be wrong as I am new to this language.
I can do it with a button but I want to do it with a asp link
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="BringPage2" />
Right now this is a link but I want to make it a button
<p>Bring Page 2 »<input id="txtBoxAlan" name="txtBoxAlan" type="text" />
Instead of redirect, I just used href as href="Default1.aspx"

asp button on click is fired on local machine but it does not fire on published server

I cannot understand why but I have a button inside a panel (attached to an Ajax Modal Popup Extender), This button onclick gets fired on local machinw but it does not work on the uploaded server online.
Do you know what might be causing this behaviour?
<asp:Button ID="btnUpsertCommodity" runat="server" Width="70" Text="Submit" OnClick="btnUpsertCommodity_Click" ValidationGroup="Commodity"/>
try setting CausesValidation property
see this for details
button CauseValidation
I encountered this error once. I'm explaining why -
Check the Page Directive of your aspx page. Here, the CodeFile="Mypage.aspx.cs" property points to the Codebehind file where the button_click event will be written. Sometimes, this codefile property contains a relative URL to the Codebehind file like this : CodeFile="~/Mypage.aspx.cs". This relative URLs does not work after Server Deployment and can't redirect a button click event to the corresponding Event Handler. Thats why, you will see the page, but clicking the button will yield nothing.
Ckeck if you have done the same. If so, just remove the ~/ part from your page directive.

JqueryMobile popup after postback

I have a Jquerymobile popup(in asp.net website) and within that I have a simple textarea and submit button.
After the submit button event, I want to do certain things.
Validation on textarea, if empty show a literal with error message.
If successful, then show a thank you message along with close button.
All this has to be done while the popup is open (after submit).
The problem is, after submit the DOM is refreshed and popup box is closed.
<div class="feedback-text">
Feedback
</div>
<div data-role="popup" id="feedback" data-overlay-theme="a" data-position-to="window">
Close
<div class="feedback-field-wrapper">
<asp:TextBox ID="txtFeedback" runat="server" Text="*feedback" cssclass="form-first-name" TextMode="MultiLine" Rows="3"></asp:TextBox>
</div>
<center>
<div class="errormsg-feedback"><asp:literal ID="ltError" runat="server" Text="test" Visible="false"></asp:literal></div>
<asp:Button ID="btnFeedback" runat="server" Text="Submit" data-ajax="false"
data-icon="arrow-r" style="width:150px;" data-inline="true" /></center>
</div>
Would you guys suggest if there is a way to keep the popup box open after the submit.
Thanks.
Unfortunately, you cant do that normally unleass otherwise you use localStorage API. This is like a cache system which exists in the browser. From DiveIntoHTML5
So what is HTML5 Storage? Simply put, it’s a way for web pages to store named key/value pairs locally, within the client web browser. Like cookies, this data persists even after you navigate away from the web site, close your browser tab, exit your browser, or what have you.
You could set a value in localStorage in the submit event of #btnFeedback, then on page refresh, check if that value exists on page refresh and reopen it.
To set a value :
localStorage["isOpen"] = "1";
To check if its null or not :
var isOpen = localStorage["isOpen"];
if ([null, undefined].indexOf(isOpen) == -1) {
//data exists
}
Demo : http://jsfiddle.net/hungerpain/ZJvjJ/
An alternate, better method would be to use ajax to submit your form. This way the page wont refresh and gives the user a nice experience.
Here's a question which helps you do that : jQuery AJAX submit form

Editing a Database Entry

I'm creating a website with ASP.net that, if you are logged in as an admin, you can edit the current pages text (this way I don't have to update the website all the time just for small changes, I can just edit the page myself while its online). All the page data is stored in a SQL Database table. Each entry is simply "ID" and "PAGECONTENT". Now, I used a SQLDataSource to get the data and put it into a FormView on my page. This all works. I made a button that is only visible if I'm logged in as the site-admin. I need to make it so when I click the button, the textlabel displaying the page content turns into a TextArea for me to edit, then I can click a "Done" button and have it update it to the Database table. I can do the updating part, I just don't know how I'm supposed to display the text in an editable manner...
You need something called a Rich Text Editor control. This will give you a Microsoft Word style interface with a toolbar etc and it will parse the html for you that you have stored in the database.
There are lots of free ones out there. A commonly used one is the one included in the Ajax Control Toolkit.
You should use nuget to install the latest Ajax Control Toolkit into your project.
There are lots of tutorials out there which explain how to use this control:
http://www.google.co.uk/search?q=asp.net+ajax+control+toolkit+htmleditor
The POST scenario: Just like you have a button that is visible only when you're logged as the site admin, have a textarea only visible when you click the edit button and have it saved when you click the done button.
A good practice would be to have a dedicated page for the edition of your db entry unless you're working with an ajax interface. It can get complicated and unsafe to POST when changing from a detail view to an edit view and to POST again when saving. That's just an idea.
The GET-then-POST scenario: have a dedicated edit page for your db entry. Let's say: /editpage.aspx?id=1. Have a done button on that page that postback and save your work.
Good luck.
http://www.w3schools.com/aspnet/control_htmltextarea.asp
maybe this is what you are looking for.
<script runat="server">
Sub submit(sender As Object, e As EventArgs)
p1.InnerHtml = "<b>You wrote:</b> " & textarea1.Value
End Sub
</script>
<html>
<body>
<form runat="server">
Enter some text:<br />
<textarea id="textarea1" cols="35" rows="6" runat="server" value="PUT_YOUR_TEXT_HERE_to_prepopulate_the_Data" />
<input type="submit" value="Submit" OnServerClick="submit" runat="server" />
<p id="p1" runat="server" />
</form>
</body>
</html>

Refresh page in asp.net

I have a webpage, in that page I have a button. How can I refresh the page when clicking on that button?
<input type="button" value="Reload" onclick="window.location.reload(true);" />
However, if the page is created from a postback, you would need to use an asp:Button control instead, and let another postback refresh the page. You also have to make sure that the correct code is executed in the code behind to recreate the correct result.
are you using an
<asp:button />
tag?
If so the page should refresh when the button is clicked by default.
<form>
<input TYPE="submit" VALUE="Submit Information Now" />
</form>
SUBMIT is a TYPE attribute value to the INPUT element for FORMs. It specifies a button that, when activated, submits the information entered to a processing script. If there are multiple SUBMIT buttons in a form, only the one activated should be sent to the form processing script.
When you press button your page must refresh, only not refresh that controls which are in AJAX Update Panel

Resources