Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 26th, 2006, 07:01 AM
Registered User
 
Join Date: Jul 2006
Location: bangalore, karnataka, India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to vikram_bendre
Default document.getElementById doesnt work in master page

Hi all,
I have implemented template.master page in default.aspx. There is one situation where in I have to access asp.net controls (dropdown boxes) in Javascript. For which I have used

var MeetingList = document.getElementById("ddlMeeting_Type_Name");

which does not seem to work at all... :(

experts!! is there any way to overcome this problem?

My guessing is since the default.aspx has no document of its own, document.getElementById is not supported...


Vikram
__________________
Vikram
Reply With Quote
  #2 (permalink)  
Old July 26th, 2006, 12:50 PM
Imar's Avatar
Wrox Author
Points: 65,660, Level: 100
Points: 65,660, Level: 100 Points: 65,660, Level: 100 Points: 65,660, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 15,962
Thanks: 64
Thanked 1,349 Times in 1,329 Posts
Default

Hi there,

Take a look at the resulting HTML in the browser. You'll find that .NET has renamed your client ID to something ctrl0_ContentPlaceHolder_ddlMeeting_Type_Name. You'll need to use that ID to reference the control.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Reply With Quote
  #3 (permalink)  
Old July 27th, 2006, 01:19 AM
Registered User
 
Join Date: Jul 2006
Location: bangalore, karnataka, India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to vikram_bendre
Default

WOW!! thanks a lot Imar, I did not even think of it
It is working fine now. thanks again

Vikram
Reply With Quote
  #4 (permalink)  
Old December 15th, 2006, 03:56 AM
Registered User
 
Join Date: Dec 2006
Location: Cluj-Napoca, , Romania.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It's better to use
document.getElementById("<%= ddlMeeting_Type_Name.ClientID %>");
Reply With Quote
  #5 (permalink)  
Old August 11th, 2010, 09:36 AM
Registered User
 
Join Date: Aug 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do you do this in a server control?

I've tried this (doesn't work):

<asp:TextBox ID="tbxSearchText" runat="server" onkeydown="if (event.keyCode == 13) document.getElementById('<%#btnSearch.ClientID%>') .click()"/>

When viewing source I see:
document.getElementById('&lt;%#btnSearch.ClientID% >').click()

And I've tried this:

<asp:TextBox ID="tbxSearchText" runat="server" onkeydown="if (event.keyCode == 13) document.getElementById('<%#btnSearch.ClientID%>') .click()"/>

When viewing source I see:
document.getElementById('&lt;%=btnSearch.ClientID% >').click()


I think the inline asp code isn't being processed. Any ideas? Thanks for your help.
Reply With Quote
  #6 (permalink)  
Old August 11th, 2010, 09:56 AM
Imar's Avatar
Wrox Author
Points: 65,660, Level: 100
Points: 65,660, Level: 100 Points: 65,660, Level: 100 Points: 65,660, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 15,962
Thanks: 64
Thanked 1,349 Times in 1,329 Posts
Default

You can add the onkeydown programmatically in code behind like this:

Code:
 
TextBox1.Attributes("onkeydown") = String.Format("alert('{0}');", Button1.ClientID)
Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #7 (permalink)  
Old August 11th, 2010, 11:45 AM
Registered User
 
Join Date: Aug 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hmm.. Still not working

I did modify it a bit, but it only seems to cause a postback. The purpose is to have the search box submit the form the same as the button does when the user presses Enter while in the text box.

Here is my aspx code:
<asp:TextBox ID="tbxSearchText" runat="server" />
<asp:Button ID="btnSearch" runat="server" Text="Go!" OnClick="btnSearch_Click" />

My Code behind:
tbxSearchText.Attributes.Add("onkeydown", "if(event.keyCode == 13) document.getElementById('" + btnSearch.ClientID + "').click();");

Viewing Source:
<input name="ctl00$tbxSearchText" type="text" id="ctl00_tbxSearchText" onkeydown="if(event.keyCode == 13) document.getElementById('ctl00_btnSearch').click() ;" />
<input type="submit" name="ctl00$btnSearch" value="Go!" id="ctl00_btnSearch" />
Reply With Quote
  #8 (permalink)  
Old August 11th, 2010, 11:50 AM
Imar's Avatar
Wrox Author
Points: 65,660, Level: 100
Points: 65,660, Level: 100 Points: 65,660, Level: 100 Points: 65,660, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 15,962
Thanks: 64
Thanked 1,349 Times in 1,329 Posts
Default

I think what you're looking for is the DefaultButton:

http://msdn.microsoft.com/en-us/libr...ultbutton.aspx
http://www.google.com/#hl=en&source=hp&q=DefaultButton

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
c:out doesnt work tllcll JSP Basics 1 November 1st, 2007 03:15 AM
Button doesnt work help john111 Java GUI 4 March 21st, 2006 04:22 PM
ContainsValue doesnt work demitry Generics 1 November 21st, 2005 04:29 PM
WHY DOESNT THIS WORK vb certified Pro VB.NET 2002/2003 5 August 1st, 2005 11:08 PM
document.getElementById(). PKC XSLT 0 July 21st, 2004 02:11 AM



All times are GMT -4. The time now is 09:12 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.