asp.net and jquery dialog - asp.net

does anyone know how to use jquery modal dialog in asp.net pages?
http://jqueryui.com/demos/dialog/
I've tried creating a simple aspx page, pasted code from the example (http://jqueryui.com/demos/dialog/), it almost works. The dialog briefly shows up and then disappears. It seems that the page is doing a postback. I'm not sure how to stop it, so that the modal dialog stays up.

I've been using jqModal for modal dialogs. I've set it up to use a standard HTML input button to trigger the dialog, and then you can put a regular asp.net button or other controls inside of the hidden div.
Hope this helps.

I assume you have something like:
<asp:Button ID="popupButton" OnClientClick="showModalPopup();" Text="Click me" runat="server" />
I would try adding "return false;" to the OnClientClick property of your Button:
<asp:Button ID="popupButton" OnClientClick="showModalPopup(); return false;" Text="Click me" runat="server" />
Or if you don't need to access the button in code-behind, simply use a standard HTML button and set it's onclick event attribute:
<button onclick="showModalPopup();">Click me</button>

Related

Asp.net Button Firing Other Button's Event

I have a set of options on an ASP.net page where the user may open up one of two lightboxes - either the "Add" lightbox or the "Edit" lightbox.
Each one has a small form for the user to fill out, and then they can hit a button at the bottom of the lightbox to hit submit.
I have the buttons set up within the lightboxes like so:
<asp:Button Id="btnSubmitAdd" runat="server" Text="Submit" OnClick="btnSubmitAdd_Click" />
... then later in the other lightbox...
<asp:Button Id="btnSubmitEdit" runat="server" Text="Submit" OnClick="btnSubmitEdit_Click" />
When i click the "Add" lightbox's submit button, everything behaves just fine.
When i click the "Edit" lightbox's submit button however, it fires "btnSubmitAdd_Click" instead of its own "...Edit_Click" event!
I have checked and re-checked all of the names and events and everything is set up correctly. Anyone have any ideas why this is happening?
Thanks to #MikeGuthrie for leading me down the correct path!
The issue seems to be with asp.net defaulting buttons to type "submit" which submits the entire form, and apparently that means it simply hit the first button's event before the second.
I added have modified the buttons like so and things are working now:
<asp:Button Id="btnSubmitAdd" runat="server" Text="Submit" OnClick="btnSubmitAdd_Click" UseSubmitBehavior="false"/>
<asp:Button Id="btnSubmitEdit" runat="server" Text="Submit" OnClick="btnSubmitEdit_Click" UseSubmitBehavior="false"/>

Submit button stops working after postback in IE11

Problem:
Sometimes submit button stops working after postback in IE11. It's
clickable, but it doesn't trigger any event. There is no script or
server side errors. Even the right click menu doesn't show on button.
If clicked somewhere on page it starts to work normally.
Button is general ASP.NET button
Server side:
<asp:Button ID="btnSave" runat="server" Text="Save" SkinID="Button82" OnClick="btnSave_Click" />
Client side:
<input name="ctl00$cphMain$Substitution$btnSave" class="button82" id="cphMain_Substitution_btnSave" type="submit" value="Save">
Any solutions?
For now I solved it using this in postback:
ScriptManager.RegisterStartupScript(Page, this.GetType(), "Refocus", "RefocusIE11()", true);
It calls function after postback, that refocuses on next element. This makes button to work again.

Using an asp.net button to launch html code

I want to use an asp.net button to launch an outlook window using the following html.
<a href="mailto:sample#website.com?subject=Insurance Text">
What do I need to do to file html code from my onClick event?
Try this
<asp:Button runat="server"
ID="btn"
OnClientClick="document.location = 'mailto:sample#website.com?subject=Insurance Text'; return false;"
Text="Mail" />
There are two approaches. If you want the standard button, you could use something like this:
<asp:Button ID="MailToButton"
Text="Send Email"
OnClientClick="javascript: navigate('mailto:blah#blah.com'); return false;"
runat="server" />
EDIT 2: Never mind about the UseSubmitBehavior property - I was incorrect. You'll just have to use return false;. Apparently ASP.NET does not render a regular non-submit button. How to disable postback on an asp Button
If you want an anchor tag, you can just use the NavigateUrl property of the Hyperlink tag:
<asp:HyperLink ID="MailToHyperlink"
Text="Send Email"
NavigateUrl="mailto:blah#blah.com"
runat="server" />
You cannot launch Outlook from the standard click event in the code behind, however. The code behind click event occurs on the server, not on the client's machine, so whatever you do it needs to happen on the client's machine either through standard HTML or through javascript.
Why an ASP.NET button?
Just use a simple HTML button.
They are plenty of example on the web. This one should work: using mailto button click event

ASP.Button - OnClientClick firing incorrectly

I have a asp.net button and I am using OnclientClick to close the window
<asp:Button ID="btnCancelSomething" runat="server" class="type-button"
Text="Cancel" OnClientClick = "Javascript:self.close()"
onclick="btnCancelSomething_Click"/>
the onclick event does nothing and I am planning to remove it. However, when I click the button the first time it is loading the page again. I click the button again then the script is fired.
How to make the window close the first time?
If the button isn't going to have any server-side functionality behind it anyway, why make it an asp:Button at all? A regular button will do the trick just fine:
<input type="button" value="Cancel" class="type-button" onclick="self.close()" />
That way it's purely client-side, since that's all the functionality that's needed anyway. It won't cause any "post-back" unnecessarily.
You could even take it a step further and break apart markup from functionality:
<input type="button" value="Cancel" class="type-button" id="cancelButton" />
Then in a script tag elsewhere, or in a separate file:
$('#cancelButton').click(function() {
self.close();
});
(Of course, this example assumes jQuery. But then what doesn't? The separation of markup and functionality if the key point here, though. How you achieve it, even how you identify the element with an id as in my example or some other way, is up to you.)

Double Postback Using IE8

I'm using ASP.NET and I have a save button on webform. When that save button is clicked (ONCE) and I'm using IE8 the event handler is executed twice. If I use compatibility mode it works just fine. In FF everything works just fine. I tested IE8 on both Vista and windows 7 and get the same behavior. IE7 works just fine. Just curious is anyone has had a similar issue.
P.S. I am using an advanced layout system which positions and styles the controls based on a layout definition, so it isn't just a standard throw controls on a page setup.
We are using onserverclick on a button tag instead of using an asp.net button. The solution was to set the type of the button to "button". Before no type was set and I think it was defaulting to submit.
Changed
<button id="button1" runat="server" onserverclick="button1_OnClick" />
To
<button id="button1" runat="server" type="button" onserverclick="button1_OnClick" />
Now I do not get the double post back in IE8.
I just fixed a bug with similar symptoms which was caused by two form.submit() calls being made in the client-side javascript event handler for the button.
It appears the second form.submit() was being ignored by other browers but executed in IE8.
I just found a solution to a similar problem I was having troubles with.
Since none of the previous solutions seemed to help me I thought I'd post my own solution.
The problem:
When using an asp button on a webform and using the OnClientClick to run a custom postback mechanism. The postback seems to happen twice (the second time without viewstate being applied)
e.g. :
function ok(){
docustompostbackthing();
}
<asp:Button runat="server" ID="btnOk" Text="Ok" OnClientClick="ok();" cssClass="btn"/>
The solution:
Add a "return false;" after the js function call in the button's OnClientClick.
Adding it in the function itself doesn't do the trick.
e.g. :
function ok(){
docustompostbackthing();
}
<asp:Button runat="server" ID="btnOk" Text="Ok" OnClientClick="ok();return false;" cssClass="btn"/>
Please look at the html as it is rendered on the page:
Every time it's present
<img src=""/>
double postback can happen, for some browser...
If this is the trouble, you can resolve it setting a default, blank, image for every button
<asp:ImageButton ImageUrl="~/Images/blank.gif"...
Just to add to the number of solutions.
It's not just OnClientClick that has issues, the OnClick event does a very similar thing in IE8 as well.
<asp:Button runat="server" ID="btnOk" Text="Ok" OnClick="ok();" cssClass="btn"/>
Can be updated to the following to avoid the second event being fired off.
<asp:Button runat="server" ID="btnOk" Text="Ok" OnClick="ok();return false;" cssClass="btn"/>
I was using jquery(formobj).trigger(submit) this was changed to
jquery(formobj)[0].submit()
Note I am calling submit directly on the form instead of the jquery method
hope this helps someone
I had this same issue happening in IE 11 and managed to fix it by adding type="button" to the button control.

Resources