Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET 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 June 23rd, 2006, 03:35 PM
Authorized User
 
Join Date: Jun 2006
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to gagansharma7
Default how to handle click event for TextBox

Hi,

      I am using a textbox & dropdownlist in a user control. I want that when the user clicks the textbox, the dropdownlist should get invisible, i wrote the following code in the page load event in .ascx.vb file:
If Not (Page.IsPostBack) Then
  textbox1.Attributes.Add("onclick", "javascript:letsgetinvisible();")
 End If

How to write code for making the dropdownlist invisible in javascript in the user control file(.ascx)?

The following code i tried, doesn't works"
<script language=javascript >
function letsgetinvisible()
{
        dropdownlist1.visible=false
}
</script>

Will someone plz. guide me? Am i trying it the correct way, or there is some other way to do it.

Regards
Gagan!

 
Old June 23rd, 2006, 05:18 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Gagan,

You should get a reference to the drop down using document.getElementById(SomeId) where SomeId is the Id of the text box. Then you should use the display (or the visibility) property of the style class:

function letsgetinvisible()
{
  document.getElementById('dropdownlist1').style.dis play = 'none';
}

Your approach is .NET code in JavaScript, which won't work at the client. You need a combination og client side JavaScript and CSS.

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old June 26th, 2006, 12:24 PM
Authorized User
 
Join Date: Jun 2006
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to gagansharma7
Default

Hey Imar,

           Thanks for your reply. I have tried what you have hinted:
document.getElementById('dropdownlist1').style.dis play = 'none';
or
document.all.item('dropdownlist1').style.visibilit y = "hidden";

It gives error: OBJECT REQUIRED
where dropdownlist1 is the id of the textbox.

also i have tried this:
document.getElementById('dropdownlist1').visible=f alse;
or
document.getElementById('<%=dropdownlist1%>').visi ble=false;

It gives error:document.getElementById() is null or not an object

Any clues for these errors?

Regards
Gagan



 
Old June 26th, 2006, 12:29 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

When you look at the resulting HTML in the browser, is the control still called dropdownlist1?

Maybe it has been prefixed by its naming container like a Repeater or a DataGrid?

Also, check the spelling and casing of the control name....

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old June 26th, 2006, 01:18 PM
Authorized User
 
Join Date: Jun 2006
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to gagansharma7
Default

Hey Imar,

            Thanks for pushing me to the right track! It worked. When i noticed the source-code in the view source, the dropdownlist was getting pre-fixed by the name of container as: CL1_dropdownlist1

document.all.item('CL1_dropdownlist1').style.visib ility = "hidden";
or
document.getElementById('CL1_dropdownlist1').style .display='none';

both are working.

Thanks again!

Regards
Gagan






Similar Threads
Thread Thread Starter Forum Replies Last Post
Help :asp.net2.0 button onclick event handle ousys Visual Studio 2005 2 November 11th, 2007 02:57 AM
Handle Infra Red event emanueletorre C# 2005 0 December 13th, 2006 06:24 AM
Handle Infra Red event emanueletorre C# 0 December 13th, 2006 06:20 AM
Mark a point in Image and handle click event on it savan_thakkar ASP.NET 1.0 and 1.1 Professional 3 June 9th, 2006 02:56 AM
Handle Sessin in browser cross button click ashish2001mca General .NET 1 February 9th, 2006 10:28 AM





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