make 2nd button on web page the default for enter key - asp.net

<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button1" />
<asp:TextBox ID="TextBox1"
runat="server">
</asp:TextBox><asp:Button ID="Button2" runat="server" Text="Button2" />
</div>
</form>
</body>
how do i make button2 the default action when the Enter key is pressed?
See image:
http://imgur.com/C9rR0

The defaultbutton property can be specified at the Form level in the form tag as well as at panel level in the <asp:panel> definition tag. The form level setting is overridden when specified at the panel level, for those controls that are inside the panel.
Source: http://forums.asp.net/t/985791.aspx/1

Related

closing the Jquery mobile panel on submit button

I have a jquery mobile panel like so:
<a href="#panel2" class="ss-header-actions-language">
<span class="ss-header-labels" id="ss-general-label">Language</span>
</a>
<div data-role = "panel" id = "panel2" data-display="overlay" data-position="right" data-swipe-close="false" >
<asp:RadioButton ID="rdbEng1" AutoPostBack="true" runat="server" Text="English" GroupName="lang" />
<asp:RadioButton ID="rdbspan1" AutoPostBack="true" runat="server" Text="Español" GroupName="lang" />
<asp:Button runat="server" Text="Submit" OnClick="Submit_Click" />
</div>
I want the panel to close when the submit button is clicked. Right now, panel closes when I select any radio button inside the panel. I want the panel to stay open if the Radio button is clicked, but as soon as I click on submit button, I want the panel to close.
How can I achieve that. Any help will be highly appreciated.
First you need to prevent postback to server, in order to do that set AutoPostBack="false" to RadioButton and you can change asp:Button to input.
Then according to JQuery Mobile Panel:
A panel can also be closed by calling the panel's close method
directly.
So this should work:
<a href="#panel2" class="ss-header-actions-language">
<span class="ss-header-labels" id="ss-general-label">Language</span>
</a>
<div data-role="panel" id="panel2" data-display="overlay" data-position="right" data-swipe-close="false">
<asp:RadioButton ID="rdbEng1" AutoPostBack="false" runat="server" Text="English" GroupName="lang" />
<asp:RadioButton ID="rdbspan1" AutoPostBack="false" runat="server" Text="Español" GroupName="lang" />
<input type="button" onclick="ClosePanel();" name="Submit" value="Submit" />
</div>
<script type="text/javascript">
function ClosePanel() {
$("#panel2").panel("close");
}
</script>

Asp.net Checkbox values not being retained in popup

We have an asp:CheckBox within an asp:DataList that appears on a popup window. Problem - the checked property values of the asp:Checkbox are not being retained. (The checked property is always false.)
NOTE - On debugging, the Page_Load method is getting called.
<div style="display: none;">
<div id="inline1">
<div class="popupbox coupons">
<asp:DataList...>
<ItemTemplate>
<asp:CheckBox id="chk1" runat="server"/>
<asp:ImageButton id="btn1" runat="server"/>
</ItemTemplate>
</div>
</div>
</div>

Client ID is not getting generated for asp.net controls

I am writing a simple webform on .net 4.0 framework.
<body>
<form id="form1" runat="server">
<div>
<span>Name</span>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</div>
<div>
<span>Email</span>
<asp:TextBox ID="txtEmail" EnableViewState="false" runat="server"></asp:TextBox>
</div>
<div>
<asp:Button ID="btnButton" runat="server" Text="Submit" />
</div>
</form>
</body>
Issue is when the form renders on browser, I am not getting ClientID for the server side controls. This is strange for me.
The portion of the markup in the browser is
<div>
<input type="submit" name="btnButton" value="Submit" id="btnButton" />
</div>
Notice there is no clientID.
Edit : Client ID something like 'ctl00$MasterPageBody$ctl00$btnButton2'
The client id of the button is btnButton. The other one "ctl..." is when you have your control inside a masterpage. As a side not: If you don´t wan´t asp.net changing your id:s you can set clientidmode='static'.
ClientID is a server side attribute.
You would see the ClientID on the client as the ID attribute:
id="btnButton"
Client id is calculated on the server, it never gets sent to the client.
You need runat="server" to generate a client ID for the control for the reasons mentioned

How is my page creating two different types of checkbox?

Got a really weird thing happening on my page. I have some checkbox controls and some of them are rendering like this..
<span confirmmodified="true" class="aspNetDisabled"><input type="checkbox" disabled="disabled" name="ctl00$FormContents$TrackerDetails$OutOfScopeUSQS" id="ctl00_FormContents_TrackerDetails_OutOfScopeUSQS"><label for="ctl00_FormContents_TrackerDetails_OutOfScopeUSQS">Out of scope USQS</label></span>
But some of them are rendering like this...
<input type="checkbox" name="ctl00$FormContents$TrackerDetails$OutOfScopeSQA" id="ctl00_FormContents_TrackerDetails_OutOfScopeSQA"><label for="ctl00_FormContents_TrackerDetails_OutOfScopeSQA">Out of scope USQS</label>
See, no span? Cant work out what is going on I have looked at the page and control and doesnt seem like anything different is happening...
UPDATE: [this is the markup]
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="AuditStateTracker.ascx.cs"
Inherits="Dashboard.controls.AuditStateTracker" %>
<div class="grid_12 alpha">
<h2><asp:Literal runat="server" Text="<%$ Resources:LocalisedText, TrackerMigration%>" /></h2>
</div>
<div class="grid_1">
<asp:CheckBox ID="OutOfScopeUSQS" runat="server" Text="<%$ Resources:LocalisedText, OutOfScopeUSQS %>" />
</div>
<div class="grid_1" runat="server" ID="divOutOfScopeSQA">
<asp:CheckBox ID="OutOfScopeSQA" runat="server" Text="<%$ Resources:LocalisedText, OutOfScopeUSQS %>" />
</div>
<div class="grid_1">
<asp:CheckBox ID="OutOfScopeRS" runat="server" Text="<%$ Resources:LocalisedText, OutOfScopeRS %>" />
</div>
<div class="grid_1" runat="server" ID="divRingFencedSQA">
<asp:CheckBox ID="RingFencedSQA" runat="server" Text="<%$ Resources:LocalisedText, RingFencedSQA %>" />
</div>
<div class="grid_1">
<asp:CheckBox ID="RingFencedRS" runat="server" Text="<%$ Resources:LocalisedText, RingFencedRS %>" />
</div>
<div class="grid_1" runat="server" ID="divBusinessCase">
<asp:CheckBox ID="BusinessCase" runat="server" Text="<%$ Resources:LocalisedText, BusinessCase %>" />
</div>
<div class="grid_1" runat="server" ID="divDelisted" visible="false">
<asp:CheckBox ID="Delisted" runat="server" Text="<%$ Resources:LocalisedText, Delisted %>" />
</div>
The first checkbox is disabled, the second one isn't; that's how asp.net renders disabled checkboxes.
It's throwing that span on there so asp.net can decorate it with the css class aspNetDisabled. This would allow you to (optionally) style disabled controls differently.
Incidentally, this disabled class is actually configurable.
In earlier versions of ASP.NET Microsoft used to render the disabled = "disabled"attribute for your controls. However, since the HTML 4.01 specification, the disabled attribute is not valid anymore for each type of web control. It is still valid for input, but not anymore for span.
So what they've done is add a style class (in CSS) which is set to controls when they are disabled. This is also the case with any controls in a diabled control. By default, this style class is called `aspNetDisabled'.
You can actually use a different name for this class, but not for individual controls. The name of this style class can only be set as a static property on the root class WebControl, for instance at application start in your global.asax.cs.
protected void Application_Start(object sender, EventArgs e)
{
WebControl.DisabledCssClass = "disabled";
}
More annoying is that for checkboxes, ASP.NET renders a span around you checkbox with the defined style class on it.
<span disabled="disabled">
<input id="ctl00_UsecaseContent_ctl01_ctl01_bCVbox" type="checkbox" name="ctl00$UsecaseContent$ctl01$ctl01$bCVbox" checked="checked">
</span>
When you are using e.g. Bootstrap as your UI framework, and on top of that a checkbox specific framework, such as https://github.com/flatlogic/awesome-bootstrap-checkbox, this additional span can actually break the structure of your HTML checkbox control hierarchy.

ASP.Net: label control in panel not updating

I have an ASP panel with a modalpopupextender attached to it that is shown dynamically. Within the panel there are two labels that are dynamically populated with text when the panel popup is shown. however, when it is shown the labels are blank (missing). Below is my code for the HTML markup and code behind:
HTML MARKUP
<asp:Panel ID="pnlalert" runat="server" CssClass="modal">
<div class="rel">
<div class="modal-inner-wrapper-alert rounded-corners">
<div class="content rounded-corners">
<div class="body">
<div class="popuppanel">
<div class="popupGnrl-Alert">
<asp:Label ID="alerttitle" runat="server" Text=""></asp:Label><br />
<asp:Label ID="alertlabel" runat="server" Text=""></asp:Label>
<asp:HiddenField ID="section" runat="server" />
<asp:HiddenField ID="violation" runat="server" />
</div>
<div class="popupGnrl-Alert" style="text-align:center;">
<asp:Button ID="cmdMaxAlertOk" runat="server" Text="Yes" Width="50px"
onclick="cmdMaxAlertOk_Click" /> <asp:Button ID="cmdMaxAlertCancel"
runat="server" Text="No" Width="50px" onclick="cmdMaxAlertCancel_Click" />
</div>
</div>
</div>
</div>
</div>
</div>
</asp:Panel>
<asp:ModalPopupExtender ID="mpealert" runat="server" TargetControlID="popuplnk" PopupControlID="pnlalert" >
</asp:ModalPopupExtender>
ASP.NET Code Behind
this.mpealert.Show();
this.alerttitle.Text = "Submission time exceeded";
this.alertlabel.Text = "This expense was incurred greater than 3 months ago and is therefore outside of the normal claim period. Do you still wish to proceed? NOTE: expense may be rejected by Finance.";
What could be causing the labels not to show?
Are you setting the text of the labels in the button event which shows the modal popup extender?
If so, the "show" event is probably being handled client side and your server side text setting code is probably never being called.
Wrap your modalpopupextender in an UpdatePanel and set it's Update condition to Always.
The above answer did not work for me. If we keep the panel inside an update panel and call the update method on update panel, then the contents get updated.

Resources