473,386 Members | 1,644 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,386 software developers and data experts.

How to get the reference of GridView footerRow in a JavaScript function

83
Hi..

I've a gridview with a footer row contains two textboxes and one button for inserting the new records to the gridview.

I want to validate the values of these text boxes on client side before entering into the database .im decided to add one javascript function..but how can i get the reference to the textboxes which are there in the footertemplate.

Thanks in advance .

BTR.
Mar 5 '09 #1
10 8412
gits
5,390 Expert Mod 4TB
in your function just use document.getElementsByTagName('input'); and then loop through the returned node list and pick the nodes you need ... check for the type attribute or wahtever you need ...

kind regards
Mar 5 '09 #2
btreddy
83
Thank you very much for the reply..

im very new to the javascript.

If you dont mind kindly please provide soem code over here.

Thanks
BTR.
Mar 5 '09 #3
gits
5,390 Expert Mod 4TB
;) the function could look like this (will check all input type='text'-nodes for empty values):

Expand|Select|Wrap|Line Numbers
  1. function validateFields() {
  2.     var val = true;
  3.  
  4.     // get the input-nodes
  5.     var nodeList = document.getElementsByTagName('input');
  6.  
  7.     // loop through the node list and break in case we find 
  8.     // an empty value in a textbox
  9.     for (var i = 0, node; node = nodeList[i]; i++) {
  10.         if (node.type == 'text' && node.value === '') {
  11.             val = false;
  12.             break;
  13.         }
  14.     }
  15.  
  16.     return val;
  17. }
kind regards
Mar 5 '09 #4
btreddy
83
Very Kind of you .

Thanks for the code.

But this function checks all the textboxes in the current document...i've somany text boxes in the current text boxes and some of them may be empty...so it would definitely break if other textboxes in the current document are empty.

How to check only the textboxes in the griviews footer row .

Thanks..
BTR.
Mar 5 '09 #5
Try this code
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2.     function chkvalue()
  3.     {
  4.  
  5.     if (document.getElementById("gvdata_ctl08_txt1").value=="" || document.getElementById("gvdata_ctl08_txt2").value=="" )
  6.     {
  7.     alert("please enter value")
  8.     }
  9.     }
  10.     </script>
Mar 5 '09 #6
gits
5,390 Expert Mod 4TB
@btreddy
i will not write the entire function for you ... in the example you just need to extend the check for a specific attribute or parent-node ... but you need to know what attribute that is ... just have a look at the html-scourcecode of the page and try it or post an example in case you have problems to implement that ...

kind regards
Mar 5 '09 #7
btreddy
83
Hey ..Its Ok .I solved it.
Expand|Select|Wrap|Line Numbers
  1. var grid=document.getElementById('ctl00_BodyContent_editgrid');
  2. if(grid!=null)
  3.     {
  4.      var text=grid.getElementsByTagName("input");
  5.      for(var i=0;i<text.length;i++)
  6.      {
  7.       if(text[i].type=='text')
  8.       {
  9.        if(text[i].value=="")
  10.        {
  11.        alert('Plese Enter the value);
  12.        return false;
  13.        }
  14.       }
  15.      }
  16.     }
  17.  
  18.  
Have a NiceTime.
BTR.
Mar 5 '09 #8
gits
5,390 Expert Mod 4TB
;) ... glad to hear that ... and you found out the best solution for yourself ... by first retrieving the parent-node and then the contained input-nodes - well done ;)

kind regards
Mar 5 '09 #9
Frinavale
9,735 Expert Mod 8TB
You should be able to get the ID of the TextBox in the FooterRow without having to loop through all of the elements on the page.

Just like you know the ID of the GridView, you also know the ID of the TextBox in the FooterRow.

If you don't actually know how to get this value, it's the ClientID property ;)

For example:

editgrid.ClientID will return "ctl00_BodyContent_editgrid" (the ID of your GridView)

So:

theTextBoxInTheFooterRow.ClientID will return you something similar to "ctl00_BodyContent_editgrid_ctrl100000theTextBoxIn TheFooterRow".

Since you can retrieve the ID of the text box in this manner, you can pass it to your validation function...or you can directly input it into your validation function...

Here's an example of your function modified to accept ID of the TextBox as a parameter:
Expand|Select|Wrap|Line Numbers
  1. function validateFooter(textBoxID)
  2. {
  3.       var textBox=document.getElementById(textBoxID);
  4.       iftextBox.value=="")
  5.        {
  6.            alert('Plese Enter the value);
  7.            return false;
  8.        }
  9.     }
There are a few ways to "directly input" it into your validation function.
If your function is in your asp page, you can use the Response.Write method to write the clientID of the TextBox into your function (note that <%= %> as an ASP short hand for calling the Response.Write method):

Expand|Select|Wrap|Line Numbers
  1. function validateFooter(textBoxID)
  2. {
  3.       var textBox=document.getElementById('<%= textBox.clientID %>');
  4.       iftextBox.value=="")
  5.        {
  6.            alert('Plese Enter the value);
  7.            return false;
  8.        }
  9.     }

Since your TextBox is going to be dynamically added to your page it's probably advisable to use the first way I mentioned (pass the ID to the function) so that in your RowDataBound event you can store the ClientID in a HiddenField.....

Ahh, there's so many ways to do this....
Mar 5 '09 #10
gits
5,390 Expert Mod 4TB
using the Id typically is good for one element ... the loop is more generic especially when more fields are added later on ... and avoids such long if-else-constructs ... but of course it is an option ;) ... a rule of thumb is to just avoid dom-operations whenever possible because they strongly affect performance ... so just try to do reduce them to a minimum ...

kind regards
Mar 5 '09 #11

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

Similar topics

1
by: tfsmag | last post by:
Hello, I have a function that returns a dynamically created gridview. This works fine, however it does not seem to be able to maintain state when adding sorting or paging to the gridview. Does...
1
by: sck10 | last post by:
Hello, I am using a GridView with 2 dropdown boxes. I would like to update the second dropdown based on the first dropdown selection. Any help with this would be appreciated. Thanks in...
3
by: Microsoft News Group | last post by:
Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more...
1
by: Microsoft News Group | last post by:
I am trying to control the visibilty of the footerrow, but having little luck. I am currently at this. if (e.CommandName == "Update") { PropertyGridView.FooterRow.Visible = true;
8
by: gerry | last post by:
The PagerSettings.Visible property is not being handled properly by the GridView control. The value assigned to this property is not applied until after a postback. Simplest test : .aspx...
2
by: shapper | last post by:
Hello, I am working with a ListView but I suppose that with a GridView might be the same. Instead of having an Insert Button on each GridView row I would like to have only one Insert button,...
3
by: ulai | last post by:
Thanks for your help. It really help to solve my work. But now i have a bigger problem : I had more than 65535 records in gridview divide by 10/pages. And when i tried to export the gridview in...
6
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...
0
by: edurazee | last post by:
I am able to create BoundFields and Footer-rows dynamically like this in my GridView: protected void Page_Load(object sender, EventArgs e) { CreateGridView(); ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.