473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Client Side Validations

I'm having a problem with client side validations. When i use the code below it breaks at line
Expand|Select|Wrap|Line Numbers
  1. 14 "var vSearch = document.getElementById("txtSearch").value;" 
When i use a simple form with a form tag it works fine, and i have all the functions setup and working on another form.
But whenever i put anything into a contentplaceholder it bugs out like crazy. Does anyone know why this happens or if there is a solution that isn't not using master pages as that's not a option i have.

[HTML]
<%@ Page Language="C#" MasterPageFile="~/MasterPages/CallCenterMaster.master" AutoEventWireup="true" CodeFile="NewSearch.aspx.cs" Inherits="Call_Center_NewSearch" Title="Ticket Search" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server" >

<script language="javascript" type="text/javascript">

function validate()
{
submitOk = "true";


var vNoData = "No data entered.";

var vSearch = document.getElementById("txtSearch").value;

if (vSearch == "")
{

document.getElementById("txtError").value = vNoData;

submitOk = "false";
}

if (submitOk == "false")
{
return false;
}


}

</script>

<table class="Backround" id="tMainSearch" style="width: 461px">
<tr>
<td style="width: 106px; height: 196px">
<table style="position: relative; left: 0px; top: 0px; width: 417px;" id="tSearch" class="Table">
<tr>
<td style="width: 162px">
</td>
<td style="width: 87px">
</td>
<td style="width: 100px">
<asp:TextBox ID="txtSearchOption" runat="server" Style="position: relative"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 162px">
<asp:Label ID="lblSearch" runat="server" Style="position: relative" Text="Search"></asp:Label></td>
<td style="width: 87px">
<asp:TextBox ID="txtSearch" runat="server" Style="position: relative"></asp:TextBox></td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td style="width: 162px">
</td>
<td style="width: 87px">
<asp:Button ID="btnSearch" OnClientClick = "return validate()" runat="server" Style="position: relative" Text="Search" /></td>
<td style="width: 100px">
<asp:TextBox ID="txtError" runat="server" Style="position: relative"></asp:TextBox></td>
</tr>
</table>
</td>
</tr>
</table>

</asp:Content>

[/HTML]
Aug 21 '07 #1
10 1489
pbmods
5,821 Expert 4TB
Heya, polydegmon. Welcome to TSDN!

We'd be able to help you a lot more efficiently if we knew what errors your script was generating ~_^

P.S., Changed thread title to better describe the problem (did you know that threads whose titles contain phrases such as, 'problem' actually get FEWER responses?).
Aug 21 '07 #2
Hi,

It gets to line 14 which is [HTML]var vSearch = document.getElementById("txtSearch").value;[/HTML]
and then does nothing else. I've tried putting in [HTML]alert("test");"[/HTML] to see just how far it goes and it never gets past line 14.
Aug 21 '07 #3
pbmods
5,821 Expert 4TB
Heya, polydegmon.

Does your code generate a JavaScript error, or does it just not do anything after that point?
Aug 21 '07 #4
Heya, polydegmon.

Does your code generate a JavaScript error, or does it just not do anything after that point?
It doesn't do anything. It should get the information from the textbox and place it in the scripted variable like it does on the forms but it just stops working and the warning message(icon) comes up at the bottom the the IE page. I figured out it was getting to that line and not working anymore by putting alert boxes in after every line and seeing when they stopped appearing. As for the exact error message it gives none.
Aug 21 '07 #5
pbmods
5,821 Expert 4TB
Heya, polydegmon.

What happens when you double-click on the warning icon?
Aug 21 '07 #6
Not much it loads to quick, but it's the general error i think like "error on page" or something like that.
Aug 21 '07 #7
pbmods
5,821 Expert 4TB
I'm stalling for time until someone with .NET experience notices this thread. Not working.

Ok. The problem that you have is that when your script calls validate(), it can't find an element whose ID is 'txtSearch'. As a result, you're probably getting an 'object expected' error, or in sane browsers, "document.getElementById('txtSearch') has no properties".

I'm not familiar enough with .NET to be able to help you out, but I will go ahead and grab a couple of Experts to see if we can't find you a solution.
Aug 21 '07 #8
Cheers, i've had the same problems looking for solutions to this myself, and usually people give a solution that uses a form rather than a master page with a contentplacehloder. :-p
Aug 21 '07 #9
I've eventually found the answer after a lot of fourm searching so here it is for anyone that has the same problem. You need to do it this way because when you use master pages each element gets uniquelly defined by the master page so this is the only way to get access to it(don't ask why haven't got a clue)

To assign the value when using master pages use :

var vSearch = document.getElementById("<%= txtSearch.ClientID %>");

To access the value use :

vSearch.value == "avalue";
Aug 21 '07 #10
pbmods
5,821 Expert 4TB
Heya, polydegmon.

Thanks for posting the solution!

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Aug 22 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: byuedwin | last post by:
Hello, I am starting a new website, and I would like to decide ahead of time what functions (in JavaScript) I will need to write on the server side and which ones on the client side. I believe...
14
by: Matt | last post by:
I want to know if ASP.NET Web Forms Validation Controls are Server-Side or Client-Side form validation? Since I think each validator control can select either 1) JavaScript based error dialog or 2)...
4
by: | last post by:
Hi Has anyone any experience using client side validation with asp.net forms. Specifically I'd like to know... 1. How do you attach client side code web controls (a button), like a...
1
by: Murat YILMAZ | last post by:
Hi all, I have develop a web page and there are 4 textbox on it. I have put 4 validation for these. Issue is that If I have request this page and submit form validations are not working. But I...
0
by: Pradeep Sundaram | last post by:
Hello, I have added an attribute "onclick" and a javascript to perform some tasks. The name of the function that needs to be called is say : confirmSave(); The problem is that the page also has...
1
by: Anup | last post by:
In my form I and doing validations using 'Javascript' as I m using ASP1.1 and there is very less support for Validators there. //Code Behind private void Page_Load(object sender,...
6
by: Charleees | last post by:
Hi all, I have a Login Page whrere all Functionalities such as validations are Done in Client Side... I have to Implement Remember My Mail Id and PAss Word Functionality also in Client side.....
6
by: ajos | last post by:
Hi friends, I guess i am asking this question in the right forum. I have a jsp page where i have a javascript date picker function enabled. This part is working perfectly, but when i tried to do a...
1
by: Shraddha | last post by:
Hi, I am adding some ASP.Net user controls (.ascx file) dynamically on the button click. The user control will get added as many times userhits the button. Now on the click of the submit button, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.