Javascript
Hello anyone der I m want to cal javascript file for validation to the backend of aspx page but aspx also contains ajax calendar toolscript how do I acheive dis..thank you
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Joginder BangerRank #360 · 7K reputationPosted Mar 15, 2015, 11:25 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 15, 2015, 8:36 PM EDT
hi,
You can return true or false to any event
for example you want to check this in change event of text box
here CheckDate java script function call first and depending upon return of this function this will make server trip i.e. if this function return true it will make server trip else not...
hope this will help you.
Anjali C64 reputationPosted Mar 15, 2015, 10:12 PM EDT
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.style1
{
text-align: left;
}
.style2
{
text-align: left;
height: 30px;
}
.style3
{
height: 30px;
}
style>
asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="register" >
<center>
<br /><br />
<table style="width: 422px; height: 279px;">
<tr>
<th class="style1">First Nameth>
<td>
<asp:TextBox ID="txtFName" runat="server">asp:TextBox>
td>
tr>
<tr>
<th class="style1">Middle Nameth>
<td>
<asp:TextBox ID="txtMName" runat="server">asp:TextBox>
td>
tr>
<tr>
<th class="style1">Last Nameth>
<td>
<asp:TextBox ID="txtLName" runat="server">asp:TextBox>
tr>
<tr>
<th class="style1">Date Of Birth<asp:CalendarExtender ID="txtDOB_CalendarExtender" runat="server"
Enabled="True" TargetControlID="txtDOB">
asp:CalendarExtender>
th>
<td>
<asp:TextBox ID="txtDOB" runat="server" ControlToValidate="TextBox5">asp:TextBox>
td>
tr>
<tr>
<th class="style1">Mobile Noth>
<td>
<asp:TextBox ID="txtMob" runat="server">asp:TextBox>
td>
tr>
<tr>
<th class="style1">EmailIdth>
<td>
<asp:TextBox ID="emailtxt" runat="server">asp:TextBox>
td>
tr>
<tr>
<th class="style1">Genderth>
<td>
<asp:RadioButtonList ID="txtGender" runat="server"
RepeatDirection="Horizontal" Height="16px" Width="188px">
<asp:ListItem>Maleasp:ListItem>
<asp:ListItem>Femaleasp:ListItem>
asp:RadioButtonList>
td>
tr>
<tr>
<th class="style2">Passwordth>
<td class="style3">
<asp:TextBox ID="txtPswrd" runat="server" TextMode="Password">asp:TextBox>
td>
tr>
<tr>
<th class="style1">Verify Passwordth>
<td>
<asp:TextBox ID="txtVerify" runat="server" TextMode="Password">asp:TextBox>
td>
tr>
table>
center><br /><br />
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
asp:ToolkitScriptManager>
<div id="button"> <center ><asp:Button ID="Button1" runat="server" onclick="Button1_Click" OnClientClick="userValid();"
Text="Register" /> center> div>
div>
asp:Content>
function userValid() {
var FName,MName,LName,dob,mob,emailid,gender,pswrd,cnfswrd;
FName = document.getElementById("txtFName").value;
MName = document.getElementById("txtMName").value;
LName = document.getElementById("txtLName").value;
dob = document.getElementById("txtDOB").value;
emailid = document.getElementById("emailidtxt").value;
gender = document.getElementById("txtGender").value;
pswrd = document.getElementById("txtPswrd").value;
cnfswrd = document.getElementById("txtVerify").value;
emailExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([com\co\.\in])+$/;
if (FName == 0 && MName == 0 && LName == 0 && dob == 0 && emailid == 0 && gender == 0 && pswrd == 0 && cnfswrd == 0)
{
alert("Enter All Fields");
return false;
}
if (FName == '') {
alert("Please Enter FirstName");
return false;
}
if (MName == '') {
alert("Please Enter Middle Name");
return false;
}
if (LName == '') {
alert("Please Enter Last Name");
return false;
}
if (dob == '') {
alert("Please enter your Date Of Birth");
}
if (gender == 0) {
alert("Please Select gender");
return false;
}
if (pswrd== '') {
alert("Please Enter Password");
return false;
}
if (pswrd != '' && cnfswrd == '') {
alert("Please Confirm Password");
return false;
}
if (pswrd != cnfswrd) {
alert("Password not match");
return false;
}
if (emailid == '') {
alert("Email Id Is Required");
return false;
}
if (emailid != '') {
if (!emailid.match(emailExp)) {
alert("Invalid Email Id");
return false;
}
}
return true;
}
so, when i execute it nothing happens and also the dob field that has an extender does not shows plz help...
Vikram AgrawalRank #4,713 · 329 reputationPosted Mar 15, 2015, 11:35 PM EDT
Hi Anjali,
you can simaplly Call your UserValid() function in button click event like below :
onclientclick='return userValid()'
Thanks
Anjali C64 reputationPosted Mar 16, 2015, 12:49 AM EDT
Vikram AgrawalRank #4,713 · 329 reputationPosted Mar 16, 2015, 1:20 AM EDT
Hi,
Is it giving any script error?
if yes then may be it is not finding your .js file, so first verify are you linked your .js file in your code properly or not.
Thanks
Anjali C64 reputationPosted Mar 16, 2015, 2:31 AM EDT
i have properly placed the javascript file but i have not placed in master page. The javascript file should be placed in master page or simply the webform i.e supported by master page?
Vikram AgrawalRank #4,713 · 329 reputationPosted Mar 16, 2015, 3:06 AM EDT
Well
if you will place your js file in master page then it will applicable for all the content pages(web pages which are using that master page) and if you place it to any web form then this js file will available only for that web form.
So put your js file in the master page like below.
thanks