ASP Disable button and run function - asp-classic

I want a webpage that will disable a button and run the function, after the page is refreshed the button will be re-enabled. The button are created with the method below. The problem is when I click on the button, it can disable but it wont runs the function, the page won't even refresh. No idea where the problem arise from.
set common = server.createobject("Pen_Ebizcommonproc.stringproc")
<%=common.writeButton ("Submit1","Submit","Create New Sales Contract",30,"onclick=""this.disabled=true;CheckGWidth(this.form);this.form.ContractType.value='N';""")%>

What I do mostly is extract it in a javascript function.
I remember that disabling a button cancels any following inline action of that button.
<form action="test.asp" method="post">
<input type="submit" onclick="doSomething(this);" />
<input type="text" id="ContractType" name="ContractType" />
</form>
Then in the javascript
function doSomething(sender)
{
sender.disabled=true;
CheckGWidth(sender.form);
sender.form.ContractType.value='N';
sender.form.submit();
}
Hope this is of any help.

I have had to do this a few time so that refreshing a page and revisiting a page is treated differently to one's first visit or after submitting one part of a form when there are more than one forms on a page, like when calculating updates for a shopping cart.
Depending on the scenario I used cookies to record the page loaded so that I could detect if it was the first visit, a refresh or what. If you have two buttons for things like "update" or "finish" they can use seperate forms with different hidden fields for mode=update or mode=finish.

Related

Validation in a modal form

I am updating our site that is used for our people to enter in orders. The first page gathers the customer information. The user currently clicks on a button that brings them to a secondary page where they can enter part of the customers name and it will return the correct customer code. The site is written in asp using sql.
I am trying, with html5, css and asp, to redesign the form so when the user clicks on the button, they will get a modal form where they can enter in part of the customers name. It would then return the id number and put it on the main page and close the modal form or it would return a not found error.
I have the asp code but where I am having an issue is how to load up the modal form. I can show a modal form from a page - but how should I handle the validation? The form itself is basically written in the html 5 page.
Thank you for your input.
George
If you are using jQuery then this is already supported. Each form element can have required to validate against empty input fields.
You can go further with changing the type attribute. For example this one requires email addresses:
<input type="email" required placeholder="Enter your email address" value="" />

Contact form 7 is posting to a url instead of posting via ajx

I am using contact form 7 plugin here (http://www.brazendev4.com/Cadental/) on right side. When I press Submit button page posts back to a url and refreshes but normally it posts via ajax and page does not refreshes. Any help will be appreciated.
Thanks in advance...
If you're planning on using ajax/js to process the form, you probably should have an empty action attribute in your form element.
e.g.
<form action="" method="post" class="wpcf7-form">
Try using the onclick attribute of the submit element to call your associated javascript function to process and post via ajax to "/Cadental/#wpcf7-f14-w1-o1".
e.g.
<input type="submit" value="Submit" onclick="MyJavascriptFunction(this.form)" class="wpcf7-form-control wpcf7-submit text2">
My guess is that before your javascript has time to process the form the DOM is posting to action="/Cadental/#wpcf7-f14-w1-o1" and reloading the page.
I see you're using jQuery in your page, so it should be easy enough to use their serialize form function to process your form.
http://api.jquery.com/serialize/
Good luck!
Best thing to do is look at the other plugins or even the theme that you are using, making sure that nothing is conflicting with CF7 which is notorious for conflicting with other javascript you use.
Check out the docs they might be able to help.
Otherwise, if the edit ability of the forms isn't important, I'd even suggest building your own form and submitting it via AJAX.
There are plenty of resources and tricks and tips around for doing this.

ASP.NET MVC3: Back button not working

So I'm using MVC3 and I am aware of the following code to return back to the original page. The location that the user was previously on.
<input type="button" class="cancel" value="Back" onclick="location.href='#Request.UrlReferrer.ToString()'"/>
So I have a Submit button, and a cancel button as above..
The problem is that when a submit fails, and is caught using server side validation.. The page it has now come from.. is itself!
So the cancel button seizes to function as expected, as it is merely refreshing the page.
How can I overcome this problem?
Is there an easy way to pass search url through the view then edit page so that I can get back to it after navigating a few pages? Without having to create and submit params on each page.
The code you're using isn't reliable. You can't 100% guarantee it will always work. You're going to have situations like this one.
There are solutions, but they're clunky and a pain. It's better to simply design your site so they are not needed. For instance, you can pass a return url as a querystring.

How is this input tag linking to another page?

Response.Write("<div><input type='submit' name='submit' value='Update Cart' /></div>")
Response.Write("<div><input type='submit' name='submit' value='Shop More' /></div>")
Response.Write("<div><input type='submit' name='submit' value='Checkout' /></div>")
that is some example code from my teacher, but he hasn't answered my email in a couple days so I need some help.
When you click the Update Cart button it just updates the cart page it's on, but when you click the Shop More button it links to Shop.aspx a different page, and the Checkout links to another page as well. I can't figure out how it is linking just from that code, anybody have any insights?
Most likely either a server side redirect has occurred, or there is some Javascript which changed the form's action. Whether that was intentional or not is yet to be determined because the given code snippet doesn't give much to work with.
By checking the value of Request.Form["submit"].ToString() you can perform a conditional operation.

Implementing Back button functionality in asp.net

i need to implement a back button for my asp.net website.I am able to use the javascript method to acheive my requirement.But using this method sometimes I need to click on the back button multiple number times to go back to the previous page.It may be because we are using jquery tabs in our website.To focus on a particular tab,other than the 1st tab on page load I am using Page.ClientScript.RegisterStartupScript(....).So I am unable to take the user back to the previous page with just one click.
I also tried with asp.net-C# methods mentioned in the following link.
http://www.dotnetcurry.com/ShowArticle.aspx?ID=89
I am able to go back to the previous page, but its state is being lost.Could someone please help me in acheiveing my requirement?
Details:
I have page1.aspx,page2.aspx(which contains jquery tabs view/edit).
In the page1.aspx there are 2 buttons(View,Edit).If I click on view button it takes me to page2.aspx View tab(1st tab) and if I click on the edit button it has to take me to page2.aspx with Edit tab loaded.both View/Edit tabs contain back button.
Also from the View tab I can navigate to the Edit tab,by clicking on another Edit button present in it.
Thanks.
The methods you have covered in your question are essentially what is available to you.
You can either
1. Provide a link that uses javascript to make the client go back a page.
2. Provide a link that posts back to the server that redirects you back a page.
I am not sure why the jquery in your webform as described in your question is causing you to click more that once to go back. If you know that it will always take 2 clicks to go back you could try this method:
javascript: window.history.go(-2)
When you are using the postback/redirect method you will always be using a http GET method to retrieve the page you are returning too. If you want to maintain state you will have to do this manually i.e. save the values when leaving the page somewhere, like session or a temporary database, and when returning to the page, during the page load, check to see if the user has these values saved and pre-populate them.
I've done something similar (with automatic redirections though) and I had to keep track of the number of pages to go back in my ViewState (or Session if you're jumping from page to page):
code-behind
public void Page_Load()
{
Session["pagesToGoBack"] = ((int)Session["pagesToGoBack"])++;
}
mark-up:
<input type="button" value="Back" onclick='javascript:history.go(<%= Session["pagesToGoBack"] %>);' />
Be careful to reset the session variable when needed
Made me feel a bit dirty but it worked :)

Resources