Set panel default button gives error, must be ibuttoncontrol - c#

I am trying to set default button for asp panel. Instead of asp button I am using button control with type="submit". I am getting error: "The DefaultButton of 'pnlSSN' must be the ID of a control of type IButtonControl.”.
This is the code I have:
<div class="input-append" id="divSSN"> <asp:Panel ID="pnlSSN"
runat="server" DefaultButton="btnSSN">
<asp:TextBox ID="txtSSN" runat="server" CssClass="span8" Width="200px"
placeholder="Enter valid Social Security Number">
ValidationGroup="validationSSN" />
<button runat="server" id="btnSSN"
onserverclick="btnSSN_Click" causesvalidation="true"
ValidationGroup="validationSSN" class="btn"
type="submit">Search</button> </asp:Panel> </div>
I also tried setting both pnlSSN.DefaultButton = btnSSN.ClientID; and pnlSSN.DefaultButton = btnSSN.ID; but I am getting the same error.

DefaultButton must be ASP.Net button server control instead of html Button
<asp:Panel runat="server" ID="pnlSSN" DefaultButton="btnSSN">
...
<asp:Button runat="server" ID="btnSSN" OnClick="btnSSN_Click" />
</asp:Panel>
Besides, your asp:TextBox tag is not well-formatted. Remove > at the end of Number">

Related

Adding Non-Standard Attribute to asp:LinkButton inside Repeater prevents the run of OnItemCommand

I am integrating a Foundation 5 Reveal Modal component with an <asp:LinkButton>. For the reveal modal to work it requires the addition of a non-standard HTML attribute data-reveal-id to the <asp:LinkButton>. If I do 'not' add this attribute in the .aspx below, then clicking the LinkButton will trigger rptNotice_ItemCommand. However, when data-reveal-id is added to the LinkButton as shown below rptNotice_ItemCommand does not run, and lbMessage is not updated. The lbMessage is required by the database upon submission of the modal form.
How do I get this to work?
Is there another way to keep track of the message ID?
In the .aspx file
<!-- Foundation 5 Reveal Modal -->
<div id="replyModal" class="reveal-modal" data-reveal>
<h2>Reply to Notice</h2>
<asp:Label ID="lbMessage" runat="server" />
<asp:TextBox ID='tbFollowQuestion' runat="server" TextMode="MultiLine" Width="100%" /><br />
<asp:Button ID="btnFollowCancel" runat="server" Text="Cancel" OnClick="followQuestionCancel_Clicked" />
<asp:Button ID="btnFollowQuestion" runat="server" Text="Submit" OnClick="followQuestionSave_Clicked" />
<a class="close-reveal-modal">×</a>
</div>
<asp:Repeater ID="rptNotice" runat="server" OnItemCommand="rptNotice_ItemCommand">
<ItemTemplate>
<div class="row padding-bottom-10 border-bottom-1 margin-bottom-10">
<!-- LinkButton -->
<div class="small-6 medium-2 xlarge-1 columns">
<asp:LinkButton data-reveal-id="replyModal" CommandName="Contact" CommandArgument='<%#Eval("MessageId")%>' ToolTip="Reply" runat="server"><img src="/images/icon/envelop.jpg" alt="Contact Us"><strong class="font-size-14">Reply</strong></asp:LinkButton>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
In the .aspx.cs file
public void rptNotice_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
lbMessage.Text = "MessageId: " + e.CommandArgument.ToObjectString();
}
There seems to be possible parsing issue due to unknown parameter. I would suggest using CommandArgument field. Try "replyModal" to CommandArgument .
Split the value at backend and get operation type.

asp panel default button property is not working in ie for live application

I have a page having multiple buttons and search functionality.I have placed one button and textbox in a panel.After writing seach text if I hit Enter,it works well for all the browsers on local, but for live application this is not working in IE.
The html is:
<asp:Panel ID="pnlSearch" runat="server" CssClass="search" DefaultButton="btnSearch">
<h2>
Explore QualityStocks without logging in</h2>
<asp:TextBox ID="txtSearch" CssClass="txt" runat="server" ToolTip="Stock Ticker" ></asp:TextBox>
<asp:Button TabIndex="0" ID="btnSearch" runat="server" ClientIDMode="Static" CssClass="btn" OnClick="btnSearch_Click" />
</asp:Panel>
What am I missing to do?
Thanks in advance,
Priya

multiple submit buttons won't postback on aspx - only last button

On my aspx page I have two fieldsets, each wrapped with an <asp:Panel DefaultButton="..."> that have their own <input type="submit"> buttons. Here's an abbreviated version...
<div id="content">...</div>
<asp:Panel runat="server" id="formPanel1" DefaultButton="form1SubmitButton">
<fieldset>
<asp:TextBox runat="server" id="textbox1"/>
<asp:TextBox runat="server" id="textbox2"/>
<asp:Button runat="server" id="form1SubmitButton" OnClick="form1SubmitButton_OnClick"/>
</fieldset>
</asp:Panel>
<asp:Panel runat="server" id="formPanel2" DefaultButton="form2SubmitButton">
<fieldset>
<asp:TextBox runat="server" id="textbox3"/>
<asp:TextBox runat="server" id="textbox4"/>
<asp:Button runat="server" id="form2SubmitButton" OnClick="form2SubmitButton_OnClick"/>
</fieldset>
</asp:Panel>
Only the last submit button form2SubmitButton will postback, the other button does nothing when clicked. I have simplified the code above but I should mention that each form, Panel included, is kept in a separate user control that is registered on the aspx.
UPDATE: After some more research I've figured out that the submits are not working because of validators on the another fieldset on the master page. That fieldset is for signing into the site, so it is needed. Thoughts?
As PCasagrande mentioned, make sure your validation groups match the default button and all validators. Specially for your logging part.
Example:
<asp:Panel ID="pnlUpdateInfo" runat="server" DefaultButton="btnUpdateInfo">
<ASP:TEXTBOX id="txtZip" runat="server"></ASP:TEXTBOX>
<asp:RequiredFieldValidator id="reqvalZipSignUp" runat="server"
ControlToValidate="txtZip" ValidationGroup="btnUpdateInfo" />
<asp:Button ID="btnUpdateInfo" runat="server" ValidationGroup="btnUpdateInfo" />
</asp:Panel>
Turns out it has to do with HTML5 constraint validation. I figured this out because in chrome, from the console, I was getting the error An invalid form control with name='...' is not focusable. This led me to this post. I added the html5 attribute formnovalidate="formnovalidate" to the submit buttons and everything works just fine (*tested in chrome v20.0.1132.57, firefox v14.0.1, IE9 v9.0.8112).
So to recap, here's the answer...
<asp:Button runat="server" id="submit1" OnClick="submit1_OnClick" text="Submit" formnovalidate="formnovalidate"/>

Submit by pressing enter asp.net

I am wondering why this, submitting on pressing enter, is only working on ie and not on google chrome...
This is the code I use actually :
<div class="TxtBox">
<asp:Panel ID="lepanel" runat="server" DefaultButton="Connect">
<asp:TextBox ID="TxtUserLogin" runat="server" TabIndex="1" Text="login" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*"
Display="Static" ControlToValidate="TxtUserLogin"></asp:RequiredFieldValidator>
<asp:TextBox ID="UserPass" runat="server" TabIndex="2" Text="password" TextMode="Password" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
Display="Static" ControlToValidate="UserPass"></asp:RequiredFieldValidator>
<asp:LinkButton ID="Connect" runat="server" OnClick="Connect_Click" TabIndex="3">connect</asp:LinkButton>
</asp:Panel>
<asp:Label ID="MsgError" runat="server" />
<div class="ForgottenPass">
forgotten password ?
</div>
<div class="RememberMe">
<asp:CheckBox runat="server" ID="chkBoxRemember" />
stay signed in
</div>
</div>
A LinkButton renders as a HTML anchor tag.
HTML anchor tags do not submit HTML forms. Therefore when you click Enter, this is not actioning any submit button.
A Button renders as HTML <input type="submit" />
An ImageButton renders as HTML <input type="image" />
These elements will both action your form.
Therefore changing LinkButton to Button or ImageButton is the best solution.
Using a LinkButton is also bad for users who do not have javascript enabled.
This is a known issue, when you add as default a link button (actually a link) and not a real button then there is a case that is not trigger properly.
So if you change it to real button you make it work.

Asp.Net popup error message

Is there a way I can display an error message in a popup box? I'm using Asp.Net (C#), and on our webpage, if an order goes throug incorrectly we display an error message. Now, we would like to be able to do so using some sort of pop-up method (maybe Ajax?) - it should be able to take a string value to display the error message.
For a simple approach, you can have a script block that contains alert("your error message"). If you want the popup to be styled as the rest of your website then you could render your error message into a div element and use a jQuery dialog to display it as a modal dialog within your page.
I have used Ajax to accomplish this myself.
Using the ModalPopupExtender and setting the PopupControlID to an Asp Panel, I usually put this into a User Control so it can be easily used through a website.
However below is a snippet of the asp.net code
<div class="modalPopupAlign">
<asp:LinkButton ID="lnkConfirm" Style="display: none;" CausesValidation="false" runat="server" PostBackUrl="#">Confirm</asp:LinkButton>
<ajax:ModalPopupExtender ID="lnkConfirm_ModalPopupExtender" runat="server" TargetControlID="lnkConfirm" PopupControlID="pnlConfirmation" BackgroundCssClass="modalBackground" DropShadow="true" RepositionMode="None">
</ajax:ModalPopupExtender>
<div id="pnlConfirmation" class="modalPopup" style="display: none;">
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="modalPopupContainerAlign">
<div>
<asp:Image ID="imgIcon" CssClass="modalPopupImage" runat="server" />
<asp:Label ID="lblMessage" CssClass="modalPopupMessage" runat="server"></asp:Label>
<div class="modalPopupTextbox"><asp:TextBox ID="txtValue" Width="200px" MaxLength="100" Visible="false" runat="server"></asp:TextBox></div>
<asp:Button ID="btnAction" runat="server" CausesValidation="false" CssClass="defaultButton" Text="OK" />
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
It does take some time to get it working properly as I have had a few errors with the script manager, which I currently have setup in a master page.
Just might give you a direction to head for, and the CSS can help shape and colour the message box.
Although this is a complex way in some respect but has many uses.
You can do this with simple javascript like this...
alert("my error message");
Here is more info on using javascript

Categories

Resources