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

Javascript Submit Problem

All,

I seem to be having an issue with calling the
'document.getElementById()' in my javascript function. I have a
checkbox where runat=server is set since I am using it in the code
behind (this is asp.net 2.0). I then have a submit button. I want to
check to see if this checkbox is checked in the javascript button. But
since the control is runat=server, whenever I call the
getElementById(checkbox) it returns a null value (can't recognize the
control).

Of course whenever I remove the runat=server it runs fine, but I need
this to be able to use in my code behind. I was wanting to know if
there is a way to reference a server object in javascript. If so.. how?
Thanks.

Nov 29 '06 #1
4 1807
Hi,

czuvich wrote:
All,

I seem to be having an issue with calling the
'document.getElementById()' in my javascript function. I have a
checkbox where runat=server is set since I am using it in the code
behind (this is asp.net 2.0). I then have a submit button. I want to
check to see if this checkbox is checked in the javascript button. But
since the control is runat=server, whenever I call the
getElementById(checkbox) it returns a null value (can't recognize the
control).

Of course whenever I remove the runat=server it runs fine, but I need
this to be able to use in my code behind. I was wanting to know if
there is a way to reference a server object in javascript. If so.. how?
Thanks.
What HTML code gets produced? What ID do you use in your getElementById?
Often, people confuse the control's ID and the ClientID. The ID is the
one you give to the control. However, this ID gets modified by ASP.NET,
because it must ensure that the ID is unique throughout the page. This
is why your server-side code must pass the ClientID to the client-side
code, using ClientScriptManager.RegisterClientScriptBlock

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Nov 29 '06 #2

Laurent Bugnion wrote:
Hi,

czuvich wrote:
All,

I seem to be having an issue with calling the
'document.getElementById()' in my javascript function. I have a
checkbox where runat=server is set since I am using it in the code
behind (this is asp.net 2.0). I then have a submit button. I want to
check to see if this checkbox is checked in the javascript button. But
since the control is runat=server, whenever I call the
getElementById(checkbox) it returns a null value (can't recognize the
control).

Of course whenever I remove the runat=server it runs fine, but I need
this to be able to use in my code behind. I was wanting to know if
there is a way to reference a server object in javascript. If so.. how?
Thanks.

What HTML code gets produced? What ID do you use in your getElementById?
Often, people confuse the control's ID and the ClientID. The ID is the
one you give to the control. However, this ID gets modified by ASP.NET,
because it must ensure that the ID is unique throughout the page. This
is why your server-side code must pass the ClientID to the client-side
code, using ClientScriptManager.RegisterClientScriptBlock

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Hey,
Thanks for the reply. How interesting is that.... The ID it gave it in
the html was ctl00_ContentPlaceHolder1_ckbUseDate. I'll do some more
research into the RegisterClientScriptBlock. Right now, I have a .js
file. Will this ID change each time the page is run.. or will that name
be constant? Thanks!

Nov 29 '06 #3
Hi,

czuvich wrote:
Hey,
Thanks for the reply. How interesting is that.... The ID it gave it in
the html was ctl00_ContentPlaceHolder1_ckbUseDate. I'll do some more
research into the RegisterClientScriptBlock. Right now, I have a .js
file. Will this ID change each time the page is run.. or will that name
be constant? Thanks!
To be honest, not very interesting ;-) It's what I told you. You give an
ID to your control on the ASPX page, but if your control runs inside
another control (user control), the framework creates a unique ID named
ClientID. In your code behind, you must get the ClientID and pass it to
JavaScript

Example with a Label in a Control:

string strScript = "<script type='text/javascript'>"
+ Environment.NewLine
+ "var strLabelClientId = " + lblTest.ClientID + ";"
+ Environment.NewLine
+ "</script>";

this.Page.ClientManager.RegisterClientScriptBlock( typeof( MyControl ),
"myScript", strScript );

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Nov 29 '06 #4
Thanks a lot! I got it working.

Laurent Bugnion wrote:
Hi,

czuvich wrote:
Hey,
Thanks for the reply. How interesting is that.... The ID it gave it in
the html was ctl00_ContentPlaceHolder1_ckbUseDate. I'll do some more
research into the RegisterClientScriptBlock. Right now, I have a .js
file. Will this ID change each time the page is run.. or will that name
be constant? Thanks!

To be honest, not very interesting ;-) It's what I told you. You give an
ID to your control on the ASPX page, but if your control runs inside
another control (user control), the framework creates a unique ID named
ClientID. In your code behind, you must get the ClientID and pass it to
JavaScript

Example with a Label in a Control:

string strScript = "<script type='text/javascript'>"
+ Environment.NewLine
+ "var strLabelClientId = " + lblTest.ClientID + ";"
+ Environment.NewLine
+ "</script>";

this.Page.ClientManager.RegisterClientScriptBlock( typeof( MyControl ),
"myScript", strScript );

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Nov 29 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Shaun Fleming | last post by:
I've been trying to make this simple script compatible across various browsers. It works for IE 6.0 and NS 7 but doesnt work with Opera (I have version 7.11). This is what is supposed to happen:...
2
by: Margaret Werdermann | last post by:
Hi all: I'm having a nasty time with a particularly difficult piece of code and was hoping someone might be able to help me. I have a FormMail form that originally worked perfectly. Then, I...
4
by: fig000 | last post by:
Hi, I'm relatively new to Javascript so please bear with me on what might sound like silly questions. This is what I want to do: I'm working in classic asp (I have to for this project). I...
6
by: Joop | last post by:
Hi all, I'm kinda new to JavaScript, but hey... I'm trying anyway! ;-) So, here's my problem : I've created a table in my document, presenting a list of items, one can 'select' by clicking...
14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
9
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work...
4
by: dschruth | last post by:
Hello. Can anybody solve this problem? I am using a server-side language (PERL) to *try* to POST data to a HTTPS login script that doesn't have a standard "submit" button. The form appears...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
5
by: Rabel | last post by:
I am a flash designer so I dont know a whole lot about the javascript submit buttons (I may not even be describing it right sorry) but here is the code I am using. <IMG name="Checkout"...
14
by: Mtek | last post by:
Hi, We have a form defined with buttons like this: <a class="save_menu" href="javascript:document.Detail_Screen.action = 'savedata.php?screen=EDIT';document.Detail_Screen.submit();">Update</...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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,...
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...

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.