I have an aspx.cs page with the following code:
hypPopup.Attributes.Add("onclick",
"window.open('Popup.aspx',
'',
'height=650,
width=800,
location=no,
toolbar=no,
status=no,
scrollbars=yes,
resizable=yes');
return false"
);
When I click the hypPopup link, the window pops up which is fine, but if I close it and refresh the page, the popup keeps popping up. I have to leave the page and come back for it to stop popping up on every refresh. Is this behavior by default or is there a fix to it?
hypPopup.Attributes.Add is done in the Page_Load
If the hypPopup button is set to run on the server, try removing that. Maybe its causing a repost and something int hat repost triggers the button click, so when you refresh the page its resimulating the repost and the click?
I don't know... just trying to think of something!
I have tested this using both <asp:Hyperlink> and <asp:LinkButton> on both Firefox 3.0.6 and IE 6, neither of which reproduce this sort of behavior. The popup window will not appear if I refresh the page (which is in fact the desired behavior since client-side events should only be fired by specific client-side actions.)
What browser are you using? Is that the exact code being fired, or is there more to it then what is displayed?
Related
There is an issue that I am facing, is to restrict user from double clicking on a command button. What it does is execute twice the code written inside it's click event. I've read many solutions for it, which I find are irrelevant. The command button, they say, should be disable after a click is performed so that user won't be able to perform another click. This will create an issue when an error occur and the code that is written to enable the button didn't execute.
Is there any other way to do it? Please suggest if any one have better option than this.
You could disable it, and put all your code within a try, catch, finally clause, and put the enabling code in finally.
Give it a read.
That way it should always run, exception or not.
I assume that you are referring to WPF, as Windows Forms has a specific double click event which can be disregarded.
Unfortunately WPF does not make a distinction between double clicking a button and clicking the button twice. This means that you have to perform the check to see if the second click occurred too soon to the first click to be regarded.
This could be done by storing the DateTime.Now in a member variable in the button click event handler and if the click occurs within a too short amount of time of the previous click, simply indicate that the button click event was handled and return without doing anything.
How to avoid modal popup closing on postback ?.. I have a popup window displaying a grid view after a buttonclick event. but the pop up closes after the button is clicked ?? Can anyone help ??
Look at this question it may help you, just recall the modalpop.show() again.
How do I prevent the closing of modal popup window(ModalPopupExtender) on postback?
In general, you will need to preserve the modal popup state in order to reinitiate it again after the postback.
What I can suggest is to setup a hiddenfield control that only holds the state of your modal (0-1, true-false, whatever you like), and with Javascript, it's easy to change the hiddenfield value in order to reflect the current popup state.
When the page get posted back and reloads again, setup an onload javascript function that checks for the hiddenfield's value, and then react based on it to show the popup again as soon as the page is loaded.
You can use an asynchronous postback or set a flag and show the dialog again after the postback.
I need to make the Enter key as Tab, changing the focus of the controls.
I tried several methods of javascript and it worked well... but in some ModalPopupExtender when i click in enter, it closes the PopUp, or in other cases that have a gridview with TextBox inside, by clicking enter it also closes a PopUp or generates a postback.
Someone have any solutions?
Thanks for the help!
I fix the problem with this code in Page_load:
GridView.Attributes.Add("onkeydown", "if(event.keyCode==13)return false;");
Thanks!
this is driving me NUTS!
i have a submit button in a header.ascx, which is in every page.
it's now a normal html submit button because i thought maybe the asp:button was giving me trouble, but as it turns out the troubles are still here.
so what happens: i click on the submit button (in the .ascx), the page reloads.... without entering the load event of the ascx.
click again... still not
then click 1 to 3 times again (random, sometimes i have to click 3 times total, sometimes 7): still not
then click again: tadaa! there is the load event breakpoint hitting....
there must be a simple reason, please tell me what it is.....
EDIT
there is some outputcaching going on ( defined in the page), posts are not cached, right??
I've got a gridview/formview, master/detail relationship going on.
When I click a button in my formview (item template), I display an ajaxcontroltoolkit modal popup.
On this popup there is a textbox (several, actually). I want to validate the data in this textbox (at least six digits, so far I'm using a regex validator) before I dismiss the popup.
The validator works, but I can still dismiss the form by clicking OK. What I'd like to do is have the ok button on the popup disabled until the data is good.
I have tried fiddling with some stuff in javascript, but I couldn't make it work, as there seems to be some issues regarding finding controls in a formview.
Any ideas?
Thanks in advance.
Without a postback
You should be able to find a control using the following technique in JavaScript:
$document.getElementById('<%=btnSubmitForm.ClientID%>').disabled = true;
If you're using RegularExpressionValidator, this forum suggests a quick (albeit hacky) way to check and see if your form is valid, without doing a postback:
http://forums.asp.net/t/1114240.aspx
With a postback
You could put the Submit button in its own UpdatePanel, if it isn't already in one, and enable/disable it in the code behind, depending on the value of the validator's IsValid property.
If you're unable to get the enable/disable functionality working, you could simply keep the modal open, so the user can't close it until they enter valid inputs or click Cancel:
protected void BtnSubmitClick(object sender, EventArgs e)
{
if (!regexValidator.IsValid)
{
modalPopupExtender.Show();
}
}