I am building a web page for creating an account for new user,
as user fill all the "Must" information, he/she clicks on create button, after submitting the values, page will be posted back to itself.
Do I need to add some cookie into the Request object and fetch it from Response object to check whether the Creations was successful or not and I can display a success message.
or by which mean I can display a creation success message on the same page.
Thanks,
Vishal
Which technology you are working on. In ASP/ASP.net, you can simply write as
Response.Write("Your Message");
If it is webforms you are using you could just add a panel (<asp:Panel />) to your markup and has it disabled/invisible as default. When you have handled your event handler just enable your panel and make it visible. The panel should contain your message.
Related
I have a legacy app that I need to change to accommodate a new payment processor.
The app is Asp.Net.
Without reconstructing the app (not in the budget) I need to take the final form and save information from it in the code behind, like it currently does, then I need to submit that same form to a third party url. Ideally as one button push to the end user.
I'm drawing a complete blank on a way to do this. Any suggestions?
Forgot to mention that JQuery and javascript are both valid tools for a solution.
You could create a javascript function that's bound to the form submit button's click event, or the form's submit event. The function will need to prevent the default form submission from firing. Use jQuery to serialize the form data, and create a synchronous AJAX request to submit the data to the third party. After the ajax submission has completed, you can trigger the form submission to the code-behind. If the ajax fails to submit properly, you can optionally abort the form submission to the code-behind.
You may need to account for XSS security, so look into cross-origin resource sharing and the Access-Control-Allow-Origin header.
Another option would be to have the code-behind behave as an http client and submit the form data to the third party.
so currently it's saving the results via code? Well, you could hack it by putting some javascript on the page that read's the forms values and posts them (eg with jquery), before doing you actual asp post.
edit (something like this might help (in some cases):
//change the action of the form (you could just change in code or this
$('#myform').attr('action','http://newpaymentproc.com/me/');
//override the default submit
$('#myformsubmitbutton').click(function(){
//extract the form data somehow (depends on form)
var formObj;
$.each($('#myform').find('input').serializeArray(), function(i, field) {
formObj[field.name] = field.value;
});
//post to old place
$.post('/old_current.asp', formObj).then(
//after posting to old place and getting response...
//submit form to new payment processor
$('#myform').submit()
);
// Cancel the actual form submit click to give time for post
return false;
});
Another way would be to have the legacy code (after submission) spit out a form with the data in it and some javascript to trigger submit on page load.
After the original process has completed, just take the submitted form data and push it to whichever URL you're working with. It requires minimal modification on the original app.
I have no code to go on, so I have no code to give. Hope that helps!
To replicate the issue:
Create an ASP.NET MVC 3 page with server validation.
Submit with validation error.
Server validation error appears in red.
Correct the validation error and submit again, then Success
redirected to another report page.
On clicking the Back button on the report page, the validation error
message still showing on the original form.
Users getting annoyed seeing the server validation message when clicking the back button.
I would not consider a solution to disable the back button.
I would not consider a solution to refresh the page on clicking the
back button.
I would consider the server validation message to disappear before making the successful form submission or any other valid solution.
Thanks
Here are some methods for clearing history so that back button will not show remembered page: http://www.codeproject.com/Tips/135121/Browser-back-button-issue-after-logout
To avoid seeing the validation message, I disable the cache so browser will automatically reload the page when users click Back button. However, users would see a form resubmission warning if the page was previously submitted using POST method. To workaround this, I use javascript window.history.back() to change a POST request back to the prior GET request if the ModelState is not valid.
Here are the details...
Create two functions in controller: one with [HttpGet] attribute and one with [HttpPost] attribute.
In the HttpPost version, add following logics...
If ModelState is invalid, save ModelState and form/model data to TempData
Return a simple View that contains javascript like following.
<html>
<body>
<script>window.history.back();
</script>
</body>
</html>
In the HttpGet version,
Add attribute [OutputCache(NoStore = true, Duration = 0)]
Add logic to load ModelState and model data from TempData
Pass model data to View
I am working on asp.net application.the user is clicks on some link which is inside grid item template field. if he is not logged in then he redirects to login page. after log in he is properly coming back to same page;the problem is that "i have passed the value in querystring to the page where he click on the link and after loggedIn the grid is showing blank because that grid is not getting query string value" I think you understand my problem.plz share your helpful opinion.
http://www.aspdotnetfaq.com/Faq/what-is-the-difference-between-server-transfer-and-response-redirect-methods.aspx
It is not a defect, but the desired behavior of Response.Redirect.
Store value in session and retrieve it after he gets back successfully from the login page.
I have this basic Drupal scenario and question:
I have a form which accepts some input from user, and a submit handler which should process data and show the result to user. In other words, I don't write anything in database or set e variables etc., just show some output to user.
I was wondering how I can do this, because a submit handler redirects the flow to another menu item -which the form values ($form_state) are not available anymore. Redirecting form to itself is not useful, because I just receive the raw posted inputs -not processed $form_state.
How can I prevent the redirection and just show some output to user in submit handler?
Thank you.
When you are building your form you want to set re-direct to false:
$form['#redirect'] = FALSE;
There is more on redirect here: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6#redirect
If I have understood your question correctly this is what you are after.
First of all, thanks for reading.
I will describe my situation as explicitly as I can.
I have a page where users can leave comments.
Here's the commenting flow
A-1. 'comment' button is clicked
A-2. a modal popup with a textbox is shown using ModalPopupExtender in ajaxtoolkit.
A-3. User types a comment in the textbox, and click "ok".
However, when user is not logged in, expected behavior changes.
B-1. 'comment' button is clicked
B-2. a Login modal-popup with id & pwd textbox is shown.
B-3. User types ID & pwd, and click ok.
B-4. Comment-modal-popup is shown
B-5. user types a comment and click ok.
I have a PROBLEM handing this case.
When B-3 occurs, page is posted back, i log the user in, update session object, and I Response.Rediect() the page to itself to display correct logged-in status (i have to..).
After redirect, in Page_Load(), I need to check some values to show Comment-Modal-Popup.
But I'm not sure how..
Here's what i considered
ViewState
i just can't use it since the page was redirected not posted back.
QueryString
I could have add "showCommentPopup=1" on URL when redirecting, but that will leave unwanted QueryString in URL. I don't want users to misuse it.
Session
I actually used Session object. Before redirection, I set Session[ "ShowCommentPopup" ] to true. In Page_Load() if it is set, i remove it and show the popup.
using Session like i did doesn't work correctly when user opens same page in multiple tabs.
user opens two tabs(in Firefox) with same URL
user follows steps from B-1 to B-3 in first tab.
before the page is redirected between B-3 and B-4, user refreshes second tab.
if the timing is right, comment-popup is shown in the second tab.
I expect to hear great insights from stackoverflow..
I haven't tried this but I think if you store your ShowCommentPopup flag in the HttpContext.Items collection instead of the session and then use Server.Transfer instead of Response.Redirect you should be able to achieve the desired results.
HttpContext.Items is a dictionary that can be used to store data whose lifetime is the lifetime of the request. This means a second request from a different tab or window will have a different HttpContext.Items dictionary.
Server.Transfer is somewhat like Response.Redirect in that it allows you to load a "different" URL instead of the original. However, while Reponse.Redirect initiates a new request, Server.Transfer transfers the existing request to the new page on the server.
A better explanation of the differences between Response.Redirect and Server.Transfer can be found here.
Example
bool showCommentPopup = false;
if (HttpContext.Current.Items["ShowCommentPopup"] != null)
{
showCommentPopup = (bool)HttpContext.Current.Items["ShowCommentPopup"];
}
//...
HttpContext.Current.Items["ShowCommentPopup"] = true;
You've clearly thought your solutions through! I'm guessing the problem with the Session was that they could comment on a different page than the one they logged into. You could get around this by storing the session var, not as a bool, but as the page to show it on:
var uniqueString = this.ToString() + uniquePageID;
if (Session["ShowCommentPage"].ToString() == uniqueString)
//show modal & remove session var
Now your program only "breaks" when the user visits the same object in two different windows, logs in on Window #1, and refreshes on Window #2. And it's not really breaking since they wind up commenting on the same object either way.
The reason I used uniquePageID, is cause I'm figuring you have a template page ("showObject.aspx") with arguments on which to show ("showObject.aspx?objectID=3"). In order to make sure the comment is left on the same ID, it needs to be present in uniqueString