ShowStandardCancelButton takes me to homepage insted of previous page - asp.net

As the topic mentions, I want to create a cancel button that takes me to the previous page. I am using the standard cancel button. I want a cancel button which only takes me one step back, to my previous page.
<wssuc:ButtonSection runat="server" ShowStandardCancelButton="true">

You can do this with javascript easily and without server control. No postbacks ;)
window.history.back();
But if you insist on a server control...
<asp:Button runat="server" OnClientClik="javascript:window.history.back();" Text="Cancel" Visible="True" />

Related

on every postback page opens in a new tab

I have a weird problem in my page. I have a button called Print. I wanted report should come in a new tab, so i wrote some javascript on button's onClientClick. Which works great with no problem at all.
But problem starts now when user comes back on original page again, now here i have several controls which cause postback. Say for example its a dropdownlist. so whenever user changes dropdown item it causes postback which is fine but everytime it opens a new tab on every postback.
hope I am clear in question...
Any help??
Here is a code:
<asp:Button ID="btnshow" runat="server" Text="Show" Font-Bold="true" ForeColor="Black" Width="90px" OnClick="btnshow_Click" OnClientClick ="document.forms[0].target = '_blank';"/>
The issue is document.forms[0].target='_blank' is setting the target on the form not the individual button so a postback triggered by any control will open in a new tab.
You should use a HyperLink control instead of the Button control. The HyperLink control has a Target property which allows you to specify how the link should be opened.
Below is an example taken from the HyperLink documentation. This will render an anchor tag with target="_blank".
<asp:HyperLink ID="lnkPrint" NavigateUrl="http://www.microsoft.com" Text="Print" Target="_blank" runat="server" />

ASP.NET Webforms OnClientClick without enter submission

I have the following command button:
<asp:Button Text="Insert Value" UseSubmitBehavior="false" runat="server" OnClientClick="return Confirmation.value('insert');" CommandName="Insert" />
I am using UseSubmitBehavior="false" to prevent ASP.Net page enter key causing post back
I do not want to listen to the enter keyCode via javascript because enter is used to submit non-webform elements not related to the form
Apparently, when using a Command and UseSubmitBehavior="false" then OnClientClick doesnt work. If I turn on submit behavior it works as expected but then hitting enter on the page automatically tries to click the button.
I prefer not to listen for the click event in Jquery or in javascript, and prefer a webform solution. Possible a better way of prevent enter from submitting the form or a way for OnClientClick to work properly with no submit behavior
You may need to use Panel and keep all your form inside Panel Tag and set the DefaultButton value of Panel to Button. Like Below:
<asp:Panel ID="Panel1" runat="server" DefaultButton="Button1">
// other form elements
<asp:Button Text="Insert Value" ID="Button1" runat="server" OnClientClick="return Confirmation.value('insert');" />
</asp:Panel>

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"/>

How can we restrict user to click a button only one time in asp.net?

I need to restrict user to click the button only one time.
I have something like this in asp.net
Can we used something like control validator or something?
<asp:Button ID="btnRegister" runat="server" Height="22px" Text="Enter" Width="100px" />
If you want the user to not click twice in a row, use javascript:
<asp:Button ... OnClientClick="this.disabled=true" />
If you want the button to be ever clicked once, the easy way is to set a cookie or session variable or something, and disable the button from code-behind.

Asp Focus on input jumping bug

I've got a web form using asp.net. In this form I have a lot of inputs.
For one of the drop downs whenever you press it, the focus jumps to the next text box.
This is in a update panel, because there is some server side work required for filtering, hiding, etc.
If the User chooses Australia from visaType_filter then it hides visaType_dd and shows visaType_tb. If they choose NZ its the other way around.
Now my question:
Is there a bug or something that makes focus jump off of a drop down when you click on it to go to the next input (or control)?
Code:
<fieldset>
<asp:UpdatePanel ID="visaTypeUpdatePanel" runat="server">
<ContentTemplate>
<label>Visa Type Number</label>
<label>
<asp:DropDownList ID="visaType_filter" runat="server" Width="40%" OnSelectedIndexChanged="visaType_filter_SelectedIndexChanged" AutoPostBack="true"/>
<asp:TextBox ID="visaType_tb" runat="server" Width="40%" OnTextChanged="visaType_tb_blur" AutoPostBack="true"/>
<asp:DropDownList ID="visaType_dd" runat="server" Width="40%"/>
<asp:Literal ID="visaType_literal" runat="server" />
</label>
</ContentTemplate>
</asp:UpdatePanel>
</fieldset>
<fieldset>
I resolved my problem by using jQuery and Ajax in place of UpdatePanels.
AFAIK, when UpdatePanel gets triggered, the focus does not get maintained. So ideally, you shouldn't be getting any focus at all.
Regardless of reason, you can work-around the issue using ScriptManager.SetFocus method to maintain focus on the drop-down.
You can also have client side solutions for maintaining focus - they essentially work by hooking into AJAX requests to remember the focused control before update panel is triggered and then restoring it back when update panel post-back is completed: see this link for one such solution.

Resources