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

referencing asp.net controls in javascript

50
hello all
i am trying to pass some text from a textbox to a dropdownlist in my asp.net page, i am using the modal popup extender and vs 2008, how do i go about referencing asp controls when writing the javascript? i have the pop up display with two textbox's and two buttons, when the ok button is clicked i want whatever is in the textboxs to go to the asp dropdown, so how would i go about doing this?

thanks
May 19 '08 #1
15 1674
acoder
16,027 Expert Mod 8TB
Check how the controls are rendered on the client-side.

If you can get the IDs and/or names it should be relatively straightforward to access the elements. If it's not easy to determine the ID/name from what the ASP.NET code looks like, use ASP.NET code to get the client-side ID and use that with document.getElementById().
May 19 '08 #2
jarremw
50
Check how the controls are rendered on the client-side.

If you can get the IDs and/or names it should be relatively straightforward to access the elements. If it's not easy to determine the ID/name from what the ASP.NET code looks like, use ASP.NET code to get the client-side ID and use that with document.getElementById().
Is that how i call an asp.net server control? like for the button 1 click event i have me.dropdownlist1.items.add(textbox2.text), the textbox that resides in the modal popup...is there a way to reference this control by just getting its id/name, or do i need to redo it in javascript?
May 19 '08 #3
acoder
16,027 Expert Mod 8TB
Show how the code is rendered in your browser.
May 19 '08 #4
jarremw
50
ok, so if use this code:

var fill
function onclick()
{
document.getelementbyid('<%=dropdownlist1.clientid %>')
}

will just using this reference that control and make the click event for the control happen?...also i am aiming this event at a contol that is in an update panel, so do i need it to do a postback?
May 19 '08 #5
jarremw
50
ok, this is what i have my modal popup extender pointing too for the onokscript..
<script type="text/javascript">
function onclick()
{

}
</script>

this is what i have in the button1 click event
Me.commentsbox.Text = "textbox1.text"

textbox1.text and button1 are in the modalpopup, so what i need to know is what ajax function do i use to call this event when the button1 is clicked so that it fills the comment box with whatever is in textbox1? i have searched google and cant find anything relating to what i am wanting to do, maybe im just searching for the wrong thing...PLEASE HELP!!!
May 20 '08 #6
acoder
16,027 Expert Mod 8TB
ok, so if use this code:
...
document.getelementbyid('<%=dropdownlist1.clientid %>')
...
will just using this reference that control and make the click event for the control happen?
JavaScript is case-sensitive, so it's document.getElementById(). The code would reference the control, but that's it. You need to call a method or set a property to actually do something with it.
May 20 '08 #7
acoder
16,027 Expert Mod 8TB
so what i need to know is what ajax function do i use to call this event when the button1 is clicked so that it fills the comment box with whatever is in textbox1?
As I've mentioned before, you need the client-side ID.

As for the filling, say you've referenced them, then the following should work:
Expand|Select|Wrap|Line Numbers
  1. // commentbox is a ref. to the comment box and textbox1 to the text box
  2. commentbox.value = textbox1.value;
  3. // if you need to add to a drop down:
  4. try {
  5.     dropdown1.add(textbox1.value,null); // standard-compliant
  6. } catch (err) {
  7.     dropdown1.add(textbox1.value); //IE-only
  8. }
Is the modal popup that you refer to a real popup window or a DHTML pseudo-popup? If it's a window, you will need to reference the window first to gain access to the elements within it from the parent page, or vice versa.
May 20 '08 #8
jarremw
50
As I've mentioned before, you need the client-side ID.

As for the filling, say you've referenced them, then the following should work:
Expand|Select|Wrap|Line Numbers
  1. // commentbox is a ref. to the comment box and textbox1 to the text box
  2. commentbox.value = textbox1.value;
  3. // if you need to add to a drop down:
  4. try {
  5.     dropdown1.add(textbox1.value,null); // standard-compliant
  6. } catch (err) {
  7.     dropdown1.add(textbox1.value); //IE-only
  8. }
Is the modal popup that you refer to a real popup window or a DHTML pseudo-popup? If it's a window, you will need to reference the window first to gain access to the elements within it from the parent page, or vice versa.
its dhtml, ok i cant try this right now because im at work, maybe on lunch, but this will be my new code....
Expand|Select|Wrap|Line Numbers
  1. function onok()
  2. {
  3. document.getElementById("textbox1")
  4. document.getElementById("dropdownlist1")
  5. try{
  6.        dropdownlist1.add(textbox1.value,null);
  7. }catch (err) {
  8.                    dropdownlist1.add(textbox1.value);
  9. }
  10.  
im using the vs2008 and when i was trying last night it kept on trying to get me to use nodevalue for some reason, is that just the way vs2008 does it?

thanks for the help so far
May 20 '08 #9
acoder
16,027 Expert Mod 8TB
Change that to:
Expand|Select|Wrap|Line Numbers
  1. function onok()
  2. {
  3. var textbox1 = document.getElementById("textbox1");
  4. var dropdownlist1 = document.getElementById("dropdownlist1");
  5. try{
  6.        dropdownlist1.add(textbox1.value,null);
  7. }catch (err) {
  8.                    dropdownlist1.add(textbox1.value);
  9. }
May 20 '08 #10
jarremw
50
ok im using this as my code
Expand|Select|Wrap|Line Numbers
  1. function onok()
  2.  
  3.       {
  4.  
  5.       var textbox1 = document.getElementById("textbox1");
  6.  
  7.       var commentbox = document.getElementById("commentsbox");
  8.  
  9.       try{
  10.  
  11.             commentsbox.nodevalue = textbox1.nodevalue;
  12.             alert(textbox1.nodeValue);
  13.  
  14.       }catch (err) {
  15.  
  16.                          commentsbox.value = textbox1.value;
  17.  
  18.       }
  19.  
and this is the modal pop up code
Expand|Select|Wrap|Line Numbers
  1. <cc1:ModalPopupExtender ID="HyperLink1_ModalPopupExtender" runat="server" 
  2.                    CancelControlID="button2" DropShadow="True" OkControlID="button1" 
  3.                    PopupControlID="panel2" TargetControlID="HyperLink1" 
  4.                    onokscript="onok()">
  5.                </cc1:ModalPopupExtender>
  6.  
when i have the popup come up and i click on the button, nothing happens, im using vs2008, so could this be the problem?
May 20 '08 #11
acoder
16,027 Expert Mod 8TB
Firstly, are the IDs on the client-side "textbox1" and "commentsbox"?

If they are, you still need to make sure you use the correct variable name. You have commentbox and commentsbox.

There's no nodeValue in JavaScript, use value instead. There's also no need for a try/catch here.

If that doesn't solve the problem, show me what the code looks like in your browser (view source).
May 20 '08 #12
jarremw
50
yeah the ids are the same...

i used this code also
Expand|Select|Wrap|Line Numbers
  1. function onok()
  2. {
  3. var textbox1 = document.getElementById("textbox1");
  4. var dropdownlist1 = document.getElementById("dropdownlist1");
  5. try{
  6.        dropdownlist1.add(textbox1.value,null);
  7. }catch (err) {
  8.                    dropdownlist1.add(textbox1.value);
  9. }
  10.  
and still nothing, does it have something to do with my button? should i make the button click event point to the ajax script? because right now all i have is the modal pop up extender onokscript event pointing to it...
May 20 '08 #13
acoder
16,027 Expert Mod 8TB
Can you post a test page link? If not, at least post the code (client-side, not .NET), so I can see where the problem might lie.
May 21 '08 #14
jarremw
50
i acutally got it to work last night, turns out i forgot that javascript is case sensitive, so my textbox id was TextBox1 and i was looking for textbox1, so when i changed to TextBox1 it started working, thanks for the help though....
also, im trying to add items to a dropdownlist that is nested in an update panel, the thing i couldnt get to work last night was the adding items to the dropdownlist, is there a way a make the updatepanel do a postback within the script?
May 21 '08 #15
acoder
16,027 Expert Mod 8TB
i acutally got it to work last night, turns out i forgot that javascript is case sensitive, so my textbox id was TextBox1 and i was looking for textbox1, so when i changed to TextBox1 it started working, thanks for the help though....
That's good. Could've been spotted if you posted the client-side code.
also, im trying to add items to a dropdownlist that is nested in an update panel, the thing i couldnt get to work last night was the adding items to the dropdownlist, is there a way a make the updatepanel do a postback within the script?
Post the relevant HTML code as it appears in the browser.
May 21 '08 #16

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

Similar topics

10
by: Data Guy | last post by:
In my approach to validation for widgets, i write javascript functions. At the end of the document, inside the form, i invoke the function as <FORM NAME="testit"> <INPUT TYPE="TEXT" VALUE="2"...
3
by: Lyners | last post by:
I have a table within a cell of a datagrid. I am doing updates without postback to the server using Javascript. I have everything working, except referencing a table within the datagrid cell. ...
3
by: DanG | last post by:
Hi I used to have an ImageButton in my datagrid, and referenced the control in the javascript with: var fld = document.getElementById('datagrid__ctl2_btnEdit'); alert(fld); //returns "" >Good...
2
by: HockeyFan | last post by:
Yesterday, I posted a question dealing with an issue of trying to reference (from javascript on the client side) an item within a Repeater. My code was hard-coded to use the actual ClientId, but...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.