Re-Enable button after submit - asp.net

I'm employing a solution similar to the answer of OnclientClick and OnClick is not working at the same time ?
How this currently works is that a file is generated and returned to the client, however after the file is returned the button should become active again.
so the response contains the file. But the button does not reactivate.
I'm not certain if this can be done.
Any thoughts?
Thanks

You could set the Id mode of the button to static. Then choose a unique Id for the button. Whenever you have verified that the file is successfully transmitted you can call (jquery):
$("#idOfSubmitButton").attr("disabled", false);

Related

Cancel button that does not send form data

Inside an UpdatePanel I have two PlaceHolders which are never visible at the same time. In one PlaceHolder I let the user choose an article to edit and when an article is selected it is displayed in the other PlaceHolder. When this happens is set the visibility of the first one to false and turn the other one on.
Now, when the user edits the article there are some fields and two buttons: one button is labeled "OK" and is used to send the form data to the server and the other button is labeled "Cancel" and is used to. It is only when the user clicks the OK-button that I need to send the form data to the server since this is the only situation where bother to handle it. Therefore, can I let the system know that the it should not send form data when the Cancel-button is clicked?
The issue was brought up because at first, I got a RequestValidation-error from the tinyMCE-component that is used for the body of the article (since it contains HTML), when I clicked the Cancel-button. Now I have turned off RequestValidation for this page and I do the validation manually.
But anyway, can I turn off form-data-sending when the Cancel-button is clicked?
Maybe if you prevent the postback when clicking the Cancel button you'll disable the form-data sending. This could be achieved by subscribing to the OnClientClick event of the button and type return false as a value.

Passing information between windows ASP.net

Here is the problem: I have a HTML page called test.html and an ASPX page called getitem.aspx.
Now what I want to do is, upon clicking a button on test.html, I want the getitem.aspx page to open in a new dialog and allow entry on a text box. After clicking the OK button on getitem.aspx, this dialog should close and the entry should be passed back to the html page.
The issue is that the getitem.aspx has several buttons that trigger postback - but I only want the item from the text box to be sent back to test.html upon clicking of the OK button and not any other buttons.
How could I implement this?
You should use javascript to do that
first you need to use window.open() method to open the popup
after you have closed the page you should use window.opener for accessing to the closed windows and use javascript method like (getElementById) to find the element on that window and read it's value and then use !!
Hope it helps

How to remove sessionvariable when closing popup window?

I have a popup window where i store an a arraylist in sessionvariable, when clicking on closebutton (the X in the right top corner) or the cmd input button in the form i want to remove the sessionvariable containing my arraylist. How can i do this?
The popup window is currently closed by a javascript:
function cmdClose_onclick() {
self.close();
}
Session variables are stored on the server, so you need to inform the server that something happened on the client, and call an appropriate function to remove the session variable.
There are a couple ways you could do this.
You could make an AJAX request to a page, a page method or a custom HTTPHandler. If you write a custom .ashx file, you could simply make a request to it's URL and have it delete the session variable.
Make your page do a postback when you close the window. You can manually trigger postbacks by calling __doPostBack() in javascript, or just executing a button click or form submit.
I'd go with option #1 if you can.
I'd suggest getting the javascript to make an AJAX call to a WebMethod which clears the session variable.

LinkButton alternative? (Need it to function like a normal link)

LinkButtons are giving me headaches. I thought, foolishly, that they allowed you to create programmatic links. Obviously this is not the case (by design), as they have behave nothing like normal links - you can't see your address when you hover over them, you can't open them in a new tab, etc.
Is there an alternative in .NET that actually lets you programmatically create a true HTML link? The ability to open multiple items in tabs is sort of a requirement. I've looked into styling a Button to look like a link, but it still behaves like a button, so this won't work either. Any ideas?
EDIT: Sorry, forgot: can't use HyperLink, as I need the ability to send CommandArguments, set OnClick events, etc. It needs to function as a button still.
The HyperLink control.
Set the href using the NavigateUrl property, and tagets (for new windows/tabs) can be set using the Target property
Edit to respond to question edit
I'm not really sure what you're after - your question is asking for a control that "functions like a normal link", so that clicking on it can open in a new window/tab, but your edit says you want to be submitting CommandArguments and using the OnClick event - so not a normal link.
The problem you've got here is that the PostBack processing of command arguments and OnClick events happens at the server, but the "open in a new window" happens on the client (using the "target" attribute of the anchor tag, or possibly with JavaScript) - these two don't really mix all that well.
A couple of options spring to mind:
Use a LinkButton, and if you handle a PostBack, output some JavaScript to open the new page in a new window.
Use a HyperLink control with a target and set the "CommandArguments" as a querystring element to the link - you can then process that on the catching page that opens in the new tab.
You can also cause JavaScript to fire onClick using the Attributes collection:
// Create a hyperlink
HyperLink link = new HyperLink();
link.NavigateUrl = "/somepage.aspx?arg=First";
link.Target = "_blank"; // Open in a new window
// Add a client side onClick event calling someMethod function with a reference
// to the link, and making sure the link processing stops.
link.Attributes.Add("onClick", "someMethod(this);return false");
You mean HyperLink?
Of course you could always use the a tag in HTML.
EDIT: When you hover over a link, the browser displays the target. When you hover over a LinkButton, the browser displays the javascript call that will execute the function server side. I'd say the best you can do is display the target page in the ToolTip, since I think it would be pretty tough to display it in the browser.
If you use a LinkButton you will be able to set the command arguments and the onclick method in your code behind. By doing so, you will no longer be able to open the link in a new window as you have found out.
One of the reasons that you cannot open a LinkButton in a new window is because it is doing a postback to the same page.
I think you either have to use a HyperLink control and pass the command argument as a query string parameter or use a LinkButton control and loose the open in a new tab functionality.
If you pass the argument as a query string parameter, then you can check for that param in page load and still call your onclick function which you were going to use for your LinkButton.
Hope this is clear and it helps you.

Confirm message in ASP.NET

I wrote this statment in my code:
Response.Write("<script language=javascript>confirm('The system not allow negative inventory,continue?');</script>");
how can I handel if the user clicked "Ok" or "Cancel" button?
You should put this confirm to your submit button like that :
btnSubmit.Attributes["onclick"] +=
"return confirm('The system not allow negative inventory,continue?');"
If user click cancel, your page won't be postback.
But if you ask you can determine user's action at server side, the answer is no, not directly. You should add some trick, to get the user's action. Maybe you should set the user's action into a hidden field and at server side get this value and continue.
Restricting my answer to Javascript and not how the result of your code would interact with the flow of the page, the Javascript confirm method returns the value of the user's selected option:
var result = confirm('The system does not allow negative inventory. Continue?');
if (result == true)
// The user wants to continue. Proceed accordingly.
else
// The user does not want to continue.
You can use the value to branch your logic accordingly.
That code will execute on the client side. To know if the user clicked OK or cancel on the server, you will need to make your script send a request back to the server. You can't handle the dialog in the same request, because your code will have ended before the user sees anything in their browser.
You could output JavaScript like this:
location.href = 'Handler.aspx?confirmed=' + confirm('Do you want to do X?');
This will send the browser to either Handler.aspx?confirmed=true or Handler.aspx?confirmed=false.
On the onClientClick tag (in the aspx file) u can write
confirm('your message');
and onClick tag reference it to function in code-behind where you can write the function which will only be executed on OK click of the messagebox.
Using a javascript confirm function it is possible to allow a user to confirm or canel a button click. If the user presses yes on the message/alert box the button click even will be triggered on the server. If the no button is click no event will be triggered. This is especially useful with buttons used for deleting.
button.Attributes("onclick") = "javascript:return " & _
"confirm('Are You Sure you want to do this operation?') "

Resources