obout textbox jquery autocomplete issue - c#

I am trying to get autocomplete feature for textboxes firstname and lastname . I m using Obout Textboxes here . The problem is , autocomplete feature is not working forthe obout control but it is working fine for asp.net input type=text control .
Note that controls are in master page.
<script type="text/javascript">
$(document).ready(function () {
$('#<%=txtFirstName.ClientID%>').autocomplete({ source: '/Controls/AutoCompleteXHandlers/UserFirstNameXHandler.ashx', appendTo: "#firstNameContainer" });
$('#<%=txtLastName.ClientID%>').autocomplete({ source: '/Controls/AutoCompleteXHandlers/UserLastNameXHandler.ashx', appendTo: "#lastNameContainer" });
});
</script>
<div id="titleDesc" runat="server">
<p style="color: Red; text-align: left; font-weight: bold">
Please use this form to Manage the User(Contractor/Govt) Account. All questions with an '*'
are required.Enter the FirstName and LastName for the Account you wish to manage.
</p>
</div>
<br />
<br />
<div id="NewRegPage" class="dvNewRegParam" style="margin-left: 20px;" runat="server">
<table id="tblManageUser" class="tblNewRegParam">
<tr>
<td style="padding: 5px 0 6px 10px;" class="td2">
<b>*First Name</b>
</td>
<td>
<obout:OboutTextBox ID="txtFirstName" runat="server" Width="220" >
</obout:OboutTextBox>
<%-- <input id="txtFirstName" type="text" runat="server" style="width: 220px" />--%>
<div id="firstNameContainer" style="width: auto"></div>
<asp:RequiredFieldValidator ID="RFVFirstName" runat="server" ControlToValidate="txtFirstName" ValidationGroup="ManageUserAccount"
Text="*First Name is required" CssClass="error" Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>

Related

Display Pop up using nested datalist details

My first 'Datalist1' retrieves some values from database i.e.,
Bus Route ID,
Vehicle number,
Trip date,
Bus source station name,
Bus Destination name
Another 'nested Datalist' which is placed inside datalist1 displays Bus icons of stages according to the number of stages between source and destination.
I succeeded to retrieving the data correctly and displayed a pop up using the above retrieved details.
<asp:DataList ID="DataList1" runat="server" RepeatColumns="1" CellSpacing="3" RepeatLayout="Table" BackColor="LightGray" OnItemDataBound="DataList1_DataBinding">
<ItemTemplate>
<table class="table">
<tr style="background-color : #b62a26; font-size:medium ; font-family:Verdana; height:40px ">
<td style="padding-left:5px">
<asp:Label ID="lblTrip" runat="server" Text="TripID:" ForeColor="White"></asp:Label>
</td>
<td style="width:900px; ">
<b> <asp:Label ID="lblTripID" runat="server" Text='<%# Eval("TripID") %>' ForeColor="White"></asp:Label></b></td>
</td>
</tr>
<tr style="background-color: white; font-size:small ; font-family:Verdana; height:60px; ">
<td colspan="2">
<b>RouteID: </b></b>
<asp:Label ID="lblRouteID" runat="server" Text='<%# Eval("RouteID") %>'></asp:Label>
<b>Vehicle NO: </b>
<asp:Label ID="lblVehicleNo" runat="server" Text='<%# Eval("VehicleNo") %>'></asp:Label>
<b>TripDate: </b>
<asp:Label ID="lblTripDate" runat="server" Text='<%# Eval("TripDate") %>'></asp:Label>
<b>From: </b>
<asp:Label ID="lblFromStage" runat="server" Text='<%# Eval("FromStage") %>'></asp:Label>
<b>To: </b>
<asp:Label ID="lblToStage" runat="server" Text='<%# Eval("ToStage") %>'></asp:Label>
</td>
</tr>
<tr style="background-color: white; font-size:small ; font-family:Verdana; height:10px ">
<td style="width:10px"></td>
<td>
<div id="activeBus" style="line-height: 0px; float: left; margin: 0px; padding: 0px; display: inline-block; vertical-align: top;">
<asp:DataList ID="innerDataList1" runat="server" RepeatColumns="10" CellSpacing="3" BackColor="white">
<ItemTemplate>
<asp:Panel ID="Panel2" runat="server" HorizontalAlign="center">
<table>
<tr style=" align-items:center ">
<td>
<asp:ImageButton ID="imgactiveBtn" runat="server" src="\images\ActiveRed.png" Width="15px" Height="15px" OnClick="imgBtn_Click" ToolTip="Track Details" />
<%-- <asp:ImageButton ID="ImageButton1" src="\images\ActiveRed.png" runat="server" Style="cursor: pointer" Width="15px" Height="15px" OnClientClick="return LoadDiv(this.src);"/> --%>
</td>
</tr>
<tr>
<td>
<b><asp:Label ID="lblStageName" runat="server" Text='<%# Eval("StageName") %>' Font-Size="XX-Small" Font-Names="Verdana" ></asp:Label></b>
</td>
</tr>
</table>
</asp:Panel>
</ItemTemplate>
</asp:DataList>
</div>
<div id="inactiveBus" style="line-height: 0px; float: left; margin: 0px; padding: 0px; display: inline-block; vertical-align: top;">
<asp:DataList ID="innerDataList" runat="server" RepeatColumns="10" CellSpacing="3" BackColor="white" OnItemDataBound="innerDataList_ItemDataBound">
<ItemTemplate>
<asp:Panel ID="Panel2" runat="server" HorizontalAlign="center">
<table>
<tr style=" align-items:center ">
<td>
<asp:ImageButton ID="imginactiveBtn" runat="server" src="\images\InActive.png" Width="15px" Height="15px" OnClick="imgBtn_Click" ToolTip="Not Reached yet!" />
</td>
</tr>
<tr>
<td>
<b><asp:Label ID="lblStageName" runat="server" Text='<%# Eval("StageName") %>' Font-Size="XX-Small" ForeColor="#CCCCFF"></asp:Label></b>
</td>
</tr>
</table>
</asp:Panel>
</ItemTemplate>
</asp:DataList>
</div>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<div id="dialog" style="display: none">
<br />
<b>RouteID:</b> <span id="RouteID1"></span> <label id="lblEmpId"></label>
<br />
<b>TripDate:</b> <span id="TripDate1"></span> <label id="lblEmpName"></label>
<br />
<b>Stage Name:</b> <span id="StageName1"></span><label id="lblEmpLocation"></label>
<br />
<b>Scheduled Arrival:</b> <span id="Scheduled_Time1"></span>
<br />
<b>Reached On:</b> <span id="Arrival_Time1"></span>
<br /><br />
</div>
Jquery code is:
$(document).on("click", "[id*=imginactiveBtn]", function () {
$("#RouteID1").html($(".RouteID", $(this).closest("tr")).html());
$("#TripDate1").html($(".TripDate", $(this).closest("tr")).html());
$("#StageName1").html($(".StageName", $(this).closest("tr")).html());
$("#Scheduled_Time1").html($(".Scheduled_Time", $(this).closest("tr")).html());
$("#Arrival_Time1").html($(".Arrival_Time", $(this).closest("tr")).html());
// Get the Current Row and its values.
var currentRow = $(this).parents("tr");
var RId = currentRow.find("span[id*='lblRouteID']").text();
var TDate = currentRow.find("span[id*='lblTripDate']").text();
var SName = currentRow.find("span[id*='lblStageName']").text();
// Populate labels inside the dailog.
$("#lblEmpId").text(RId);
$("#lblEmpName").text(TDate);
$("#lblEmpLocation").text(SName);
$("#dialog").dialog({
title: "Track Vehicle at <em>" + SName + "</em>",
buttons: {
Ok: function () {
$(this).dialog('close');
}
},
modal: true
});
return false;
});
    
For example let us assume on 12/10/2017, 2 Trips were active with RouteID's 1 & 2, and each Routes has 3 stages.
When the first stage of route 1 is clicked Popup should display:
Route ID: Route1
TripDate: 12/10/2017
Stage Name: Stage1
When second icon is clicked Popup should should display
RouteID: Route1
TripDate: 12/10/2017
Stage: Stage2 and so on...
Similarly when Stages of Route2 is clicked
Route ID: Route2
TripDate: 12/10/2017
Stage Name: Stage1
and when he clicks second stage of Route 2
Route ID: Route2
TripDate: 12/10/2017
Stage Name: Stage2 and so on.....
But Popup displays:
RouteID: Route1Route2
TripDate: 12/10/201712/10/2017
StageName: Stage1Stage2Stage3Stage1Stage2Stage3
for all the 3 stages of Route1 and for all the 3 stages of Route2.
How can i resolve this. Where am i doing it wrong?

linkbutton are not posting back in asp.net

I have many linkbutton placed on a webform everything working correctly til yesterday. But now now my ajax extenders are not working and linkbuttons are posting back.
some of my code is
<table width="460px">
<tr>
<td colspan="2"
style=" color: #C48239; font-style: normal; font-size: 18px; font-family: 'Bookman Old Style'; text-align:center;height:22px;">
Manage Your Profile</td>
</tr>
<tr>
<td>
<asp:LinkButton ID="lnk_per_pro" runat="server" CssClass="linkButton"
PostBackUrl="~/User/Edit_profile.aspx">Edit Personal Profile</asp:LinkButton> </td>
<td>
<asp:LinkButton ID="lnk_par_pro" runat="server" CssClass="linkButton">Edit Partner's Profile</asp:LinkButton></td>
</tr>
<tr>
<td>
<asp:LinkButton ID="lnk_con_det" runat="server" CssClass="linkButton"
PostBackUrl="~/User/Edit_profile.aspx">Edit Contect Details</asp:LinkButton></td>
<td>
<asp:LinkButton ID="lnk_add_photos" runat="server" CssClass="linkButton">Add Photos</asp:LinkButton></td>
</tr>
<tr>
<td>
<asp:LinkButton ID="lnk_hob" runat="server" CssClass="linkButton"
PostBackUrl="~/User/Edit_profile.aspx">Edit Hobbies and Interests</asp:LinkButton></td>
<td>
<asp:LinkButton ID="lnk_del_pro" runat="server" CssClass="linkButton">Remove/Delete Profile</asp:LinkButton></td>
</tr>
</table></center>
</div>
</div><!-- div 2 end-->
<div id="div3">
<div id="inbox1"><b>About Myself</b>
</div>
<div id="inbox2">Partner Prefrence
</div>
</div>
<div id="div4">
<div id="indiv4"><b>Basics Information</b>
<div id="edit4">
<asp:LinkButton ID="lnk_edit" runat="server" CssClass="link"
PostBackUrl="~/User/Edit_profile.aspx"> Edit</asp:LinkButton> <img src="images/edit.png" alt="" />
</div>
</div>
<div id="indiv24">
<div id="lt"><table class="style1" >
<tr>
<td style="color: #666666; width: 180px">
Age</td>
<td style="width: 180px">
<asp:Label ID="lbl_age2" runat="server" Text="Label"></asp:Label>
</td></tr><tr>
<td style="color: #666666; width: 180px">
Mobile Number</td>
<td>
<asp:Label ID="lbl_mob2" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td style="color: #666666; width: 180px">
Height</td>
<td style="width: 180px">
<asp:Label ID="lbl_height2" runat="server" Text="Label"></asp:Label>
</td></tr><tr>
<td style="color: #666666; width: 180px">
Email Id</td>
<td>
<asp:Label ID="lbl_eml2" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td style="color: #666666; width: 180px">
Marital Status</td>
<td style="width: 180px">
<asp:Label ID="lbl_mar_sts2" runat="server" Text="Label"></asp:Label>
</td></tr>
</table></div>
a link is shown on hover of linkbutton
javascript:webforms_DoPostbackWithOption:(NewPostBackoption("","false",true,"false"));
Do you have any validation controls inside application , check once by setting the Cause validation = false to link button control .
Some times your system has changed to old time(like one year back) also the link buttons won't redirect
There may be validation controls inside application , check once by setting the Cause validation = false to link button control .

asp net repeater radio button group name and get radio button value

I have an aspx c# page for bank account numbers and credit card installment list in one page
if user want to bank transfer it choose bank account else if user want to pay credit card installment it did it.
the problem is radio buttons group name. I didn't group the radio buttons and didn't get the selected radio button value.
Here is my codes.
This İs Bank Account List
<asp:Repeater ID="RptBankalar" runat="server">
<ItemTemplate>
<div class="BankaListBox">
<table width="100%" height="100" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="200" align="center" valign="middle">
<img alt="<%#Eval("BankName").ToString() %>" src="../../Files/<%#Eval("Logo").ToString() %>" /></td>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="120" height="22"><strong>Account Owner</strong></td>
<td width="15"><strong>:</strong></td>
<td><%#Eval("AcOwner").ToString() %></td>
</tr>
<tr>
<td width="120" height="22"><strong>Branch No</strong></td>
<td width="15"><strong>:</strong></td>
<td><%#Eval("Branch").ToString() %></td>
</tr>
<tr>
<td width="120" height="22"><strong>Account Number</strong></td>
<td width="15"><strong>:</strong></td>
<td><%#Eval("AccountNum").ToString() %></td>
</tr>
<tr>
<td width="120" height="22"><strong>IBAN</strong></td>
<td width="15"><strong>:</strong></td>
<td><%#Eval("Iban").ToString() %></td>
</tr>
</table>
</td>
<td width="100" align="center" valign="middle">
<asp:RadioButton ID="RadioBtn" Text='<%#Eval("id").ToString() %>' runat="server" />
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:Repeater>
Same Page Credit card installment list
<asp:Repeater ID="RptTaksitList" OnItemDataBound="RptTaksitList_ItemDataBound" runat="server">
<ItemTemplate>
<tr runat="server" id="arka_tr">
<td align="center" height="22" width="40" runat="server" id="td1">
<b style="display: none; visibility: hidden">
<asp:Literal ID="lt_id" Text='<%#Eval("BankaID").ToString() %>' runat="server"></asp:Literal>
</b>
<asp:Literal ID="lt_taksit_sayisi" Text='<%#Eval("TaksitSayisi").ToString() %>' runat="server"></asp:Literal></td>
<td width="150" runat="server" id="td2">
<asp:Literal ID="LblSepetTotal" runat="server" Text='<%#Session["SepetUrunToplami"] %>'></asp:Literal></td>
<td runat="server" id="td3"><b style="display: none; visibility: hidden">
<asp:Literal ID="lt_komisyon_orani" Text='<%#Eval("KomisyonOrani").ToString() %>' runat="server"></asp:Literal>
</b>
<asp:Literal ID="lt_toplam_tutar" runat="server" Text=''></asp:Literal>
<b style="display: none; visibility: hidden">
<asp:Literal ID="lt_alt_limit" Text='<%#Eval("AltLimit").ToString() %>' runat="server"></asp:Literal>
</b>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
How can i get the values and grouping this radio buttons.
Normally i did in classic asp but i change my coding language.
Kindly regards.
Thanks for your helps.
i never help in Stack. So i will contribute for the first time after been helped so many times by the community.
I hove you like. I have a more simple solution.
Surround your radio button with some element (DIV) with a className that you might like just to pick all the radio in jQuery.
EDITED IN: The aspnet wasnt persisting the viewstate when i changed that way. Now it works just fine :)
$(document).ready(function () {
$(".radiofix").each(function () {
var objRadiosContainer = $(this);
objRadiosContainer.find("input[type=radio]").each(function () {
var objRadio = $(this);
objRadio.change(function () {
if(objRadio.get(0).checked)
{
objRadiosContainer.find("input[type=radio]").each(function () {
if($(this).get(0).id != objRadio.get(0).id)
{
$(this).get(0).checked = false;
}
});
}
});
});
});
});
Let's take a look in the HTML file (or ASPX file):
<asp:Repeater ID="questions" runat="server">
<ItemTemplate>
<h3>%# getQuestionNumber() %>) <%# Eval("questionDescription").ToString() %></h3>
<div class="nameOfTheClass">
<asp:Repeater ID="answers" runat="server">
<ItemTemplate>
<asp:RadioButton ID="radioId" runat="server" />
</ItemTemplate>
</asp:Repeater>
</div>
</ItemTemplate>
This you will work just fine. Just create some javascript file (.js) and call it, fixTheRadios.js and choose a name for "nameOfTheClass" that you like.
Important: I didnt tested the code inside an update panel. I suggest you do that.
Here's how I do it.
In the markup I declare the radio button as server side html control:
<input id="rbMyRadio" type="radio"runat="server" class="myClass" />
And in the code access the value:
foreach (RepeaterItem item in RptBankalar.Items)
{
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
HtmlInputRadioButton rbMyRadio = (HtmlInputRadioButton)item.FindControl("rbMyRadio");
if (rbMyRadio != null && rbMyRadio.Checked)
{
//Do tasks
}
}
}
Grouping is done using jquery in page head:
<script type="text/javascript">
$(document).ready(function () {
$('input[type=radio]').click(function () {
var cname = $(this).attr('class');
$('.' + cname).each(function () {
$(this).prop('checked', false);
});
$(this).prop('checked', true);
});
});
</script>
And reference jquery in the head:
<script src="Scripts/jquery-1.8.2.js"></script>
Very late answer but you can also try adding the radio buttons like this in the repeater:
<asp:TemplateColumn>
<ItemTemplate>
<div style="text-align: center">
<input type="radio" id="rptMyRadio" runat="server" />
</div>
</ItemTemplate>
</asp:TemplateColumn>
Then in a script block add:
$('input[type=radio]').click(function () {
$('input[type=radio]').removeAttr("checked");
$(this).prop('checked', true);
});

Checkbox selected within hidden div

I have a C# Checkboxlist within a hidden div. The div displays upon certain events, then is closed. When the form is submitted, I try to update database bit fields based on selected values of the checkboxlist.items but they always return false whether checked or not. How can I get the selected value of the items when the div containing them is hidden?
The div is a dialog I show/hide using jquery
$(document).ready(function () {
$('#<%=txtLANG.ClientID %>').click(function () {
$("#overlay-back").dialog({
resizable: false,
modal: true,
width: 500,
height: 400,
buttons: {
OK: function () {
GetLanguages();
$(this).dialog("close");
},
Cancel: function () {
$(this).dialog("close");
}
}
});
});
});
and here's the DIV...the codebehind is nothing more than setting a parameter to true/false based on selected value of the checkboxlist items
<div id="overlay-back" style="display:none;">
<table width="100%">
<tr>
<td width="50%">
<asp:CheckBox runat="server" ID="chkEnglish" TextAlign="Right" Text=" English" />
<div class="popup-container">
<img id="help_button_chkEnglish" class="help-button" src="/Images/help-button.png" alt="" />
<div class="help-popup hidden" id="help_popup_chkEnglish">
<div class="popup-arrow-border"></div> <div class="popup-arrow"></div>
<asp:Label runat="server" ID="lblLANGDesc"></asp:Label>
</div>
</div>
</td>
<asp:Panel runat="server" ID="pnlTopLanguages">
<td rowspan="3" valign="top">
<asp:CheckBoxList ID="chkTopLanguages" TextAlign="Right" runat="server" />
<br />
<asp:Label runat="server" ID="lblNonTopLanguages"></asp:Label><br />
<asp:TextBox runat="server" ID="txtOtherLanguages" onkeypress="CopyOtherLangs(event)" onclick="clearLanguageSearchText()" Text="Other Languages..."></asp:TextBox>
<cc3:AutoCompleteExtender ID="aceSearch" runat="server" MinimumPrefixLength="1" TargetControlID="txtOtherLanguages"
ServicePath="~/controls/wsCommunity.asmx" ServiceMethod="GetLanguageCompletionList">
</cc3:AutoCompleteExtender>
</td>
<td rowspan="3">
<div class="popup-container">
<img id="help_button_chkTopLanguages" class="help-button" src="/Images/help-button.png" alt="" />
<div class="help-popup hidden" id="help_popup_chkTopLanguages">
<div class="popup-arrow-border"></div> <div class="popup-arrow"></div>
<asp:Label runat="server" ID="lblTopLangs"></asp:Label>
</div>
</div>
</td>
</asp:Panel>
</tr>
<tr>
<td>
<asp:CheckBox runat="server" ID="chkFrench" TextAlign="Right" Text=" French" />
<div class="popup-container">
<img id="help_button_chkFrench" class="help-button" src="/Images/help-button.png" alt="" />
<div class="help-popup hidden" id="help_popup_chkFrench">
<div class="popup-arrow-border"></div> <div class="popup-arrow"></div>
<asp:Label runat="server" ID="Label2"></asp:Label>
</div>
</div>
</td>
</tr>
<asp:Panel runat="server" ID="pnlEnhancedFrench">
<tr>
<td valign="top">
<asp:CheckBoxList ID="chkEnhancedFrench" TextAlign="Right" CssClass="EnhancedFrench" runat="server">
<asp:ListItem> Customer Service</asp:ListItem>
<asp:ListItem> Publications</asp:ListItem>
<asp:ListItem> Website</asp:ListItem>
<asp:ListItem> Interpreters</asp:ListItem>
</asp:CheckBoxList>
</td>
</tr>
</asp:Panel>
</table>
</div>

Field Validator Fires undesirably

I have a page with the following mark up
<%# Page Title="" Language="C#" MasterPageFile="~/CaseAdmin.master" AutoEventWireup="true" CodeBehind="AddExhibit.aspx.cs" Inherits="Prototype5.AddExhibit" %>
<h2 class="style2">
<strong><span style="color: #FFFFFF">Add Exhibit
Form</span></strong></h2>
<div style="width: 600px">
<table style="width: 303px" align="left">
<tr>
<td class="style26" style="background-color: #666666">
<p class="style5" style="color: #000000; background-color: #666666;">
<strong style="background-color: #666666">Select Existing Case ID:
</strong>
</p></td>
<td class="" style="background-color: #C0C0C0" align="left">
<asp:DropDownList ID="DropDownListcaseid" runat="server"
onselectedindexchanged="DropDownListcaseid_SelectedIndexChanged">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="DropDownListcaseid"
ErrorMessage="Please select a valid case id from the dropdown menu"
ForeColor="Red">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style4" colspan="2">
</td>
</tr>
</table>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CMSSQL3ConnectionString1 %>"
SelectCommand="SELECT [CaseID] FROM [Cases]"></asp:SqlDataSource>
</div>
<div style="width: 603px; height: 75px; ">
<table style="height: 66px; width: 598px; top: 277px; left: 268px;"
align="left">
<tr>
<td class="bold"
style="color: #000000; background-color: #666666; width: 127px;">
<strong>Exhibit Type</strong></td>
<td class="bold" style="background-color: #666666; width: 228px;">
<span style="color: #000000">Exhibit Image</td>
<td class="bold" style="background-color: #666666; width: 111px;">
<span style="color: #000000">Stored Location</span></td>
<td class="bold" style="background-color: #666666; color: #000000;">
Officer ID</span></td>
</tr>
<tr>
<td class="style32" style="background-color: #C0C0C0; width: 127px;">
<asp:DropDownList ID="exhibitTypeDropDownList" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Hard Disk</asp:ListItem>
<asp:ListItem>Pen Drive</asp:ListItem>
<asp:ListItem>Laptop</asp:ListItem>
<asp:ListItem>Palm Devce</asp:ListItem>
<asp:ListItem>Mobile Phone</asp:ListItem>
<asp:ListItem>Tablet PC</asp:ListItem>
<asp:ListItem>Pager</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="exhibitTypeDropDownList"
ErrorMessage="Please Enter the type of exhibit. eg. Harddisk"
ForeColor="Red" ondisposed="addExhibitButton_Click">*</asp:RequiredFieldValidator>
</td>
<td class="style28" style="background-color: #C0C0C0; width: 228px;">
<asp:FileUpload ID="exhibitImageFileUpload" runat="server" />
</td>
<td class="style20" style="background-color: #C0C0C0; width: 111px;">
<asp:DropDownList ID="storedLocationDropDownList" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>B-15/4</asp:ListItem>
<asp:ListItem>B-10/1</asp:ListItem>
<asp:ListItem>B-5/4</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="storedLocationDropDownList"
ErrorMessage="Please enter a valid stored location" ForeColor="Red"
ondisposed="addExhibitButton_Click">*</asp:RequiredFieldValidator>
</td>
<td class="style30" style="background-color: #C0C0C0">
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="officersSqlDataSource" DataTextField="PoliceID"
DataValueField="PoliceID" Width="79px" Height="26px">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="DropDownList1"
ErrorMessage="Please select a valid Officer id from the dropdown list"
ForeColor="Red" ondisposed="addExhibitButton_Click">*</asp:RequiredFieldValidator>
</td>
</tr>
</table>
</div>
<div style="width: 609px; height: 23px;">
</div>
<div style="margin-top:12px; width: 232px; text-align:left; font-size:1.3em;">
<asp:SqlDataSource ID="officersSqlDataSource"
runat="server"
ConnectionString="<%$ ConnectionStrings:CMSSQL3ConnectionString1 %>"
SelectCommand="SELECT PoliceID FROM PoliceOfficers"></asp:SqlDataSource>
<table align="left">
<tr>
<td align="center">
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="Red"
HeaderText="The following errors occured." />
</td>
</tr>
</table>
</div>
<div style="margin-top:12px; width: 456px;">
<table style="width: 450px" align="left">
<tr>
<td align="center" colspan="3">
<asp:Label ID="messageLabel" runat="server" BackColor="White" ForeColor="Red"
Visible="False"></asp:Label>
</td>
</tr>
<tr>
<td align="center" style="width: 96px">
<asp:Button ID="cancelButton" runat="server" Text="Cancel"
onclick="cancelButton_Click" height="26px" width="101px" />
</td>
<td style="width: 237px">
</td>
<td align="center">
<asp:Button ID="addExhibitButton" runat="server" Text="Add Exhibit"
onclick="addExhibitButton_Click" />
</td>
</tr>
</table>
</div>
and the following interface look
I wish to perform validation on the page only when the "add exhibit button" is clicked. so in my code behind, i used an "if(page.isvalid)" to check for page validation when the button is clicked. However any other button i click fires the validation as well... I presume its because every button click tries to load a page and that calls the validator to action. how do i allow work around the validation such that, only the " add exhibit button" triggers the page validation?
You need to set the ValidationGroup property on the button and the validator. That way you can control what validation takes place.
The ValidationGroup property is an arbitrary tag that you can add to your validators and buttons to group them into logical units. So in your case, I would do this:
For your validators that are relevant for the add exhibit action.
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" ValidationGroup="AddExhibit" ...
For your button that triggers your add exhibit.
<asp:Button ID="addExhibitButton" ValidationGroup="AddExhibit"

Categories

Resources