Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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
 
Old July 26th, 2006, 12:50 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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
 
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
 
Old December 15th, 2006, 04: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 %>");
 
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.
 
Old August 11th, 2010, 09:56 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
 
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" />
 
Old August 11th, 2010, 11:50 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!




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 05:22 PM
ContainsValue doesnt work demitry Generics 1 November 21st, 2005 05: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.