Required Validator and compare validators do not work! - c#

I am trying to see the validation part working. I have few required field validators and compare field validators, etc.
<div>
<asp:RequiredFieldValidator ID="rfvCompany" ValidationGroup="groupProfile"
ControlToValidate="txtCompany" runat="server"
ErrorMessage="- Company Name Required" Display="Dynamic" />
</div>
<div>
<asp:RequiredFieldValidator ID="rfvAddress" ValidationGroup="groupProfile"
ControlToValidate="txtAddress" runat="server"
ErrorMessage="- Address 1 Required" Display="Dynamic" />
</div>
This is my save button, validation has to happen when this button is clicked.
<tr>
<td align="center">
<asp:ImageButton ID="btnSave" runat="server" ImageUrl="~/images/green-save.gif"
OnClick="btnSave_Click" TabIndex="22" ValidationGroup="groupProfile" />
</td>
</tr>
The popup that comes when the save button is clicked is this..
<tr>
<td colspan="2" align="left" style="padding-left: 75px; padding-top: 10px;">
Do you wish to update the Location Information as well.
</td>
</tr>
<tr>
<td align="center" colspan="4">
<asp:Button ID="btnYesMerchant" Text ="Yes" runat="server" class="popupButton"
causesvalidation="true" OnClientClick="$find('mdlpop').hide(); return true;"
onclick="btnYessave_Click"/>
<asp:Button ID = "btnNoMerchant" Text ="No" runat ="server" class="popupButton"
causesvalidation="true" OnClientClick="$find('mdlpop').hide(); return true;"
onclick="btnNosave_Click"/>
<asp:Button Id="btnCancel" Text ="Cancel" runat="server" class="popupButton" />
</td>
</tr>
Where am i doing wrong? i am in a serious mess, i guess :(

Ensure you have included the asp:ScriptManager on your page. In addition to that check for javascript errors and (if any) add them to your question.

Here i have assigned the popup to the button, so the popup is being called when the button is clicked. Now i have changed the flow. For the button, i have written a javascript function that will validate and calls the popup to show if validation is passed. This worked. Thank you all..

Related

Checkbox inside Update Panel causing full post back

I have registration form for users to fill up. In there, one field is there to which if user checks on the button a text box shoulld be enabled to enter the number. I have used following code :
<asp:UpdatePanel ID="upMSME" runat="server">
<ContentTemplate>
<tr>
<td colspan="2">
<asp:Label ID="lblMSME" runat="server" Text="Whether covered under MSME (Tick whichever is applicable)"></asp:Label>
<asp:CheckBox AutoPostBack="true" Checked="true" ID="chbMSME" runat="server" OnCheckedChanged="chbMSME_CheckedChanged" ClientIDMode="AutoID"/>
</td>
</tr>
<tr id="trMSMENo" runat="server">
<td>
<asp:Label ID="lblMSMENo" runat="server" Text="MSME Number" CssClass="alignTop"></asp:Label>
</td>
<td class="ValueBox">
<asp:TextBox ID="txtMSMENo" runat="server" MaxLength="75"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvMSMENo" runat="server" ForeColor="Red" ErrorMessage="*" ControlToValidate="txtMSMENo" ValidationGroup="vgVendor"></asp:RequiredFieldValidator>
</td>
</tr>
</ContentTemplate>
</asp:UpdatePanel>
However I searched over internet and found that by setting the ClientIDMode="AutoID" the issue is resolved. But in my case after setting the property there is still full postback occurred.
I have another update panel also in this form, does it make any difference?
What am I missing?

html input of type File wrapped inside ASP: Panel is not disabled when panel is disabled

I have wrapped HTML Input control of type File inside ASP:Panel control(which is wrapped inside update panel).
When I disable ASP:Panel control, input control is still enable. Please helpme out
ASPX Code :
<asp:Panel ID="pnlBrowseCSV" runat="server" Enabled="true">
<table>
<tr>
<td align="left" valign="top" style="height: 30px; width: 160px;">
<strong>CSV File:</strong>
</td>
<td style="height: 30px">
<input type="file" id="csvFile" runat="server"
onkeydown="return false" style="width: 350px; background-color:white"/>
<strong>(*.csv)</strong>
</td>
<td style="height: 30px">
<ASP:Button ID="btnValidate" Text="Validate" runat="server"
OnClick="btnValidate_Click" />
</td>
</tr>
</table>
</asp:Panel>
Using visible attribute instead of Enabled.
<asp:Panel ID="pnlBrowseCSV" runat="server" Visible="False">
This issue is by design. What you can do rather is write one extra line of code to disable File upload where you disable the panel.
pnlBrowseCSV.Enabled = false;
csvFile.Enabled=false;

How to invoke Html button control in repeater control

Below is my code,can anyone please guide me in invoking the html button on repeater control.
Mark up:
<asp:Repeater ID="rptList" runat="server" onitemcommand="rptList_ItemCommand1">
<HeaderTemplate>
<table id="tbllist">
<tr>
<th>Qty</th>
<th width="100%" align="left">Item</th>
<th></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="center"><%# Eval("Quantity")%></td>
<td align="left"><%# Eval("ItemName")%></td>
<td align="center"><input id="Button1" runat="server" commandname="btnAdd" type="button" value="Addtocart" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
.CS file code:
protected void rptList_ItemCommand1(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
if (e.CommandName == "btnAdd")
{
Response.Write("hello,I am a button.");
}
}
You have used input without runat="server"
Change
<input id="btnAddtocart" type="button" value="Addtocart" />
To
<input id="btnAddtocart" runat="server" type="button" value="Addtocart" CommandName="CommandName"/>
Use asp:button instead of input type="button"
<asp:Button ID="btnAddtocart" runat="server" CommandName="CommandName"/>
You have used input without runat="server", You need to add runat="server" to make a button server button control and perform postback
Change
<input id="btnAddtocart" type="button" value="Addtocart" />
To
<input id="btnAddtocart" runat="server" type="button" value="Addtocart" />
Use asp:button instead of input type="button" if you do not have any particular reason for using it.
<asp:Button ID="btnAddtocart" runat="server" Text="Addtocart" CommandName="Addtocart"/>

Yes No Cancel (3 buttons) for AJAX Modalpopupextender

Does Ajax ModalPopupExtender has an option to create 3 buttons? Yes, No and Cancel? for ASP.NET WebForms, C#
I could not come up with a solution. I can just find OKControlID and CancelControlID.
<table id="pnlPopupMerchantUpdate" runat="server" style="display:none">
<tr>
<td>
<asp:Panel runat="server" CssClass="modalPopup">
<table width="350" height="80" class="warningPopup">
<tr>
<td>
<!-- <img src="images/warning_blue.gif" alt="Warning" /> -->
</td>
<td colspan="2" align="left" style="padding-left: 75px; padding-top: 10px;">
Do you wish to update the Location Information as well.
</td>
</tr>
<tr>
<td align="center" colspan="4">
<input id="btnYesMerchant" type="button" value="Yes" class="popupButton" causesvalidation="true" onclick="btnYessave_Click"/>
<input id="btnNoMerchant" type="button" value="No" class="popupButton" causesvalidation="true" onclick="btnNosave_Click" />
<input id="btnCancel" type="button" value="Cancel" class="popupButton"/>
</tr>
</table>
</asp:Panel>
</td>
</tr>
Here, I do want to call different functions for Yes and No.
Instead of OKontrolID, you can use extender's client side API to hide it on button's on-click event. See this article that shows multiple cancel button - your scenario is similar, you just need to return true from your button's onclick event handler.
<ajaxToolkit:ModalPopupExtender runat="server" BehaviorID="myPopup" ...
and
<input id="btnYesMerchant" type="button" onclick="$find('myPopup').hide(); return true;" ...
Thought i found it to be so tough, it is simple to handle this problem. We just got to add return true for each asp button.
ANd remove the OKCOntrolID from ModalPopupExtender. It solved my problem. Thanks all who gave it a try reading.

Button not firing onClick below Panel controls in IE

I have a button which is not working when placed below two panels. If I move it above the panels, it works.
It works either way in Firefox. It does not work in IE 8
The button runs this code
protected void Button2_Click(object sender, EventArgs e)
{
panelForm.Enabled = true; //input panel
panelOutput.Visible = false; //output panel
Button1.Visible = true; //input panel button
}
I have some workarounds, but was hoping to find the cause of the issue.
edit: here is the markup of the second panel and button. I've tried moving the button outside of the panel and get the same result.
<asp:Content ID="MainContent" Runat="Server" ContentPlaceHolderID="MainContentPlaceHolder">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="domainUserID" runat="server" Visible="false"></asp:TextBox>
<!-- gray bar and title -->
<table style="width:100%; border-style:none;">
<tr>
<td class="com_headline">
SQL Emergency Request [Home]
</td>
</tr>
<tr class="com_app_instructions">
<td>
<p>Words here</p>
</td>
</tr>
</table>
<!-- end title and gray bar -->
<asp:Panel ID="panelForm" runat="server" Visible="True" CssClass="myform">
<form method="post" action="Default.aspx" id="form">
<h1>Request Form</h1>
<p>Complete this form to be issued a login</p>
<table cellpadding="5px">
<tr>
<td>
IR Number
<br />
<span class="small">Obtain your IR number from
SMART</span>
</td>
<td>
<asp:TextBox ID="txtIR" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtIR" CssClass="errorMsg"
ErrorMessage="Please Enter Your IR Number">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Server
<br />
<span class="small">MSSQL5 is supported for now</span>
</td>
<td>
<asp:DropDownList ID="ddServer" runat="server" AutoPostBack="True"
Enabled="False" onselectedindexchanged="ddServer_SelectedIndexChanged">
<asp:ListItem>DEVMSSQL05</asp:ListItem>
<asp:ListItem Selected="True">MSSQL05</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="ddServer" CssClass="errorMsg"
ErrorMessage="Please Choose A Server">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Database
<br />
<span class="small">You have the role of 'Analyst' in these databases</span>
</td>
<td>
<asp:DropDownList ID="ddDatabase" runat="server" AppendDataBoundItems="true"
AutoPostBack="false" DataSourceID="DatabaseDropDownObjectDataSource"
DataTextField="DatabaseName" DataValueField="DatabaseName" Width="150">
</asp:DropDownList>
</td>
<td>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="Button1" runat="server" CssClass="com_btn_flat"
onclick="Button1_Click" Text="Submit" />
</td>
<td>
<div id="loader">loading...</div>
</td>
</tr>
</table>
</form>
</asp:Panel>
<asp:Panel ID="PanelError" runat="server" Visible="false" CssClass="errorPanel">
<h1><asp:Label ID="txtErrorMsg" runat="server">error text</asp:Label></h1>
</asp:Panel>
<br />
<asp:Panel ID="panelOutput" runat="server" Visible="false" CssClass="panelOutput">
<h1>
<asp:Literal ID="Title" runat="server" Text=""/>
</h1>
<p>
<asp:Literal ID="Warning" runat="server" Text=""/>
</p>
<p>
<asp:Literal ID="LoginLifeHours" runat="server" Text=""/>
</p>
<p>
<span class="important">
<asp:Literal ID="Login" runat="server" Text="" />
</span>
</p>
<p>
<span class="important">
<asp:Literal ID="PWD" runat="server" Text="" />
</span>
</p>
<br />
<p>
<asp:Button ID="Button2" runat="server" Text="Request Another Login"
onclick="Button2_Click" CssClass="com_btn_flat" />
</p>
</asp:Panel>
This is the button that is not responding in IE
<p>
<asp:Button ID="Button2" runat="server" Text="Request Another Login"
onclick="Button2_Click" CssClass="com_btn_flat" />
</p>
The problem is that you are using a <form> tag within your content page. The master page already includes a <form> tag and IE appears to be balking at the form within a form. When I removed the <form> tag from your aspx, the button handler ran under IE8.
The sample code is Button2_Click, but your button markup outside of the panels has test_button_Click as the event handler? There are three buttons, so which one are you asking about, I assume the last?
I noticed that you have a tag inside your first panel (panelForm). Also, I don't see a a tag with a runat="server" attribute (although, it could be in a master page). And it doesn't look like your button is inside a form (unless the master page has a form).
The problem is that you can only have one form on a page in Asp.NET WebForms. If you don't have any <form runat="server"> tags on your page, then you buttons will not fire any events on the code-behind.

Categories

Resources