 |
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
|
|
|

July 26th, 2006, 07:01 AM
|
Registered User
|
|
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

July 26th, 2006, 12:50 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

July 27th, 2006, 01:19 AM
|
Registered User
|
|
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
WOW!! thanks a lot Imar, I did not even think of it
It is working fine now. thanks again
Vikram
|

December 15th, 2006, 04:56 AM
|
Registered User
|
|
Join Date: Dec 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
It's better to use
document.getElementById("<%= ddlMeeting_Type_Name.ClientID %>");
|

August 11th, 2010, 09:36 AM
|
Registered User
|
|
Join Date: Aug 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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('<%#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('<%=btnSearch.ClientID% >').click()
I think the inline asp code isn't being processed. Any ideas? Thanks for your help.
|

August 11th, 2010, 09:56 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You can add the onkeydown programmatically in code behind like this:
Code:
TextBox1.Attributes("onkeydown") = String.Format("alert('{0}');", Button1.ClientID)
Cheers,
Imar
|

August 11th, 2010, 11:45 AM
|
Registered User
|
|
Join Date: Aug 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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" />
|

August 11th, 2010, 11:50 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
|
|
 |