473,698 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript validation Gridview FooterTemplate

83 New Member
Hii Experts,

im facing a problem with the javascript validation.i've a gridview in my web form and added a footer tempalte and placed textboxes in tht tempalte ,just to add a new row to the gridview and i wanna to validate the emalid entered in the footertextbox of the gridview. so i added a javasript function :
Expand|Select|Wrap|Line Numbers
  1.  function OnCheckEmailID(srcID)
  2.     {
  3.  
  4.        var email=document.getElementById(srcID);     
  5.        var filter =/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
  6.        if (!filter.test(email.value)&& !email.value=="") 
  7.        {         
  8.           alert('Please provide a valid email address');
  9.           email.value="";
  10.           email.focus();   
  11.           return false;            
  12.        }
  13.        else
  14.         return true;
  15.  
  16.     }
and i linked this function to the change event of my text box in the source code like this:
Expand|Select|Wrap|Line Numbers
  1. <asp:TextBox ID="txtdummy" runat="server" Width="150px" OnChange="OnCheckEmailID('ctl00_BodyContent_txtdummy')" ></asp:TextBox>
But unfortunately this is not working ...but for testing purpose i placed one textbox outside the gridview and i linked the javascript function to the textchange event in the same ..thn its working fine...

so the function is getting called for the textboxes outside the gridview..but not for the textboxes in the footer template of the gridview.

can anybody tell me what im missing ..

Thanks in Advance..
Rgds,
BTR.
Feb 9 '09 #1
12 9896
btreddy
83 New Member
can anybody help me in finding the solution for this.

Thanks

Rgds,
BTR.
Feb 10 '09 #2
kenobewan
4,871 Recognized Expert Specialist
Isn't onchange the html input event through which to call JS events. Easiest way to get OnCheckEmailID working is therefore to change textbox to html input. Otherwise use server side code.
Feb 10 '09 #3
btreddy
83 New Member
Thanks for your reply. everytime you are only replying to my queries .Thanks for your time.

Its working now.

But may i know the reason why its behaving like this..coz its working for other textboxes which are outside of the gridview.

And when i try to call the JS function for the OnTextChanged instead of OnChange event of the server side Textbox i.e. <asp:Textbox> ,i got the runtime error..".too many characters in the literal".

Requesting you kindly explain me whts going on behind the scenes.

Rgds,
BTR.
Feb 10 '09 #4
Frinavale
9,735 Recognized Expert Moderator Expert
I'm not sure what's causing the problem but have you considered using a RegularExpressi onValidator instead?

Add one to your footer template and see if it works...
Feb 10 '09 #5
btreddy
83 New Member
Dear kenobewan,

If you dont mind can you please tell me how can i do this validation on server side,instead of client side.like when i click on the Insert button which is there in the Footertemplate of the gridview it has to validate the footer textbox control's text and alert the user if he enters no value otherwise proceed for the insertion operation.

As you know we dont have MessageBox facility in ASP.NET.

Please Help me .

Rgds,
BTR.
Feb 11 '09 #6
btreddy
83 New Member
Hii,

I found that the ClientID( i.e.in the HTML source) of the textboxes which are there in the footer template of the Gridview is changing ,its not constant .and also its looks to be diffrent

'ctl00_BodyCont ent_editgrid_ct l64_tbmail' this is the ID of a textbox with id=tbmail which is thr in the footertemplate;

and for others the id is "ctl00_BodyCont ent_dvMeetingDe tail_txtorganiz ername"

if we compare the both the diffrece is ,ct164 is added which is not constant and keep on changing.some times its 160 and sometimes its 162 and today its 164.

Is this is the reason why its not geting the reference of the textbox controls which are placed in the footer row of a gridview.

Kindly help me..

Rgds,
BTR.
Feb 11 '09 #7
Frinavale
9,735 Recognized Expert Moderator Expert
Change your JavaScript to accept a TextBox as the parameter.


So your function wouldn't change much....just pass it the TextBox element instead of the ID of the TextBox element:
Expand|Select|Wrap|Line Numbers
  1. function OnCheckEmailID(src)
  2.     {
  3.  
  4.        var email=src;     
  5.        var filter =/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
  6.        if (!filter.test(email.value)&& !email.value=="") 
  7.        {         
  8.           alert('Please provide a valid email address');
  9.           email.value="";
  10.           email.focus();   
  11.           return false;            
  12.        }
  13.        else
  14.         return true;
  15.  
  16.     }


You would pass the function the TextBox like so:
Expand|Select|Wrap|Line Numbers
  1. <tdummy" runat="server" Width="150px" OnChange="OnCheckEmailID('this')" ></asp:TextBox>
This would get around the problem with the changing ClientID.
Feb 11 '09 #8
btreddy
83 New Member
Dear Frinavale,

Thanks for the reply.

I changed the javascript function as you said ..but unfortunately its also not wroking.

and when i try to debug the javascript function in Visual studio 2005,wht i found is tht its not getting the footer textbox reference...but getting null value and its breaking immediatly..

I passes the name of the textbox as a parameter to the javascript function and chnged the function accrodingly ..thn also the same problem.

Really getting irritated with this strange behaviour..god knows wht's the problem is.

Rgds,
BTR.
Feb 12 '09 #9
btreddy
83 New Member
Dear kenobewan and Frinavale,

You both please help me...im in the middle of the ocean.

Rgds,
BTR.
Feb 12 '09 #10

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

Similar topics

0
1822
by: Lee Moore | last post by:
I have the following code, which I thought should work. I get an error stating ... Could not find control 'GOAL_TEXT_CONTROL' in ControlParameter 'GOAL_TEXT'. Any help would be great. <-------------------------- Code Snippet ---------------------------> <asp:GridView ID="GridView1" Runat="server"
2
6546
by: Robert Smith jr. | last post by:
Hello, Please pardon my newbie question ... I am building an ASP.NET page that displays a recordset with a Delete statement enabled (this all works fine). I want to Insert the current row *that is going to be deleted* into another table, before the original data is deleted. I am trying to use the RowDeleting method to call an Update or Insert
7
17313
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi all! I have a gridview inside a datagrid (nested) for which (gridview) the rowcommand is not raised in order to delete a row from the grid! I also tried OnRowCommand="method", didn't work either! Does anyone know how can I make this work? Thanks in advance!
0
1977
by: KeesH | last post by:
Hi, I am quite desperate now because I made a nice webshop with a gridview where the customer is able to update the amount of products (Hostas in my situation) or delete the row. The problem is that every works really fine with this code when customers order approximatelly a maximum of 35 products. What I learned so far is to set the EnableViewState="False" for all the labels that don't need a viewstate. This helped a lot. What can I do...
0
1542
by: seanmatthewwalsh | last post by:
This should be REALLY straightforward. I have a gridview that allows editing, deleting and inserting (from the footer row). There is a Drop Down ListBox in the one column, which needs to ALWAYS set to a default value (but not always the same value, so I can't set it declaritively. It will ultimately depend on a session variable as to which default to use). However, the point is that the DDL in the footer (insert) row must ALWAYS be set,...
0
1585
by: Andy B | last post by:
I have a GridView with a LINQDataSource attached to it. My code in the aspx markup is below. I need to know why only the checkbox field for the activated column is getting updated (the EditTemplate). None of the other columns get updated except for that one. Any ideas? The only column that is not able to be updated is the ID column, but that isn't even in the table. <asp:GridView ID="EternityNewsMemberList" runat="server"...
6
4272
by: Ahmedhussain | last post by:
Hi there, I m doing work on a gridview and Im getting an error: A potentially dangerous Request.Form value was detected from the client (ctl00$Content$GridView1$ctl03$TextBox1="<span class='txtColo...") Im using an access database. and when ever I try to update this it doesnt work. <%@ Page Language="C#" MasterPageFile="Mysite.master" Title="Untitled Page" %> <script runat = "server"> protected void Page_Load(object sender,...
0
4181
parshupooja
by: parshupooja | last post by:
Hey All, I have where I want to do some manipulations and show in other column but unable to find their values in RowDatabound event even though I have two records in gridview <asp:GridView ID="GridView1" runat="server" ShowFooter="True" AutoGenerateColumns="false" Width="700px"> <Columns> <asp:TemplateField HeaderText="Qty"> <EditItemTemplate> <asp:TextBox...
1
3790
by: janetb | last post by:
I have a gridview with an update capabilities - a textbox column (roomName), a dropdownlist(orgID), a dropdownlist(roomTypeID),a checkbox column (dialOut), a checkbox column (dialIn). When I try to add another checkbox column, the sql database isn't updated properly with a 0/1 or false/true but with null. I've tried everything I can think of. Can anyone help? Data command stuff: UpdateCommand="update telehealth.dbo.xTblRoom...
0
8609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7739
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.