Click here to Skip to main content
15,075,638 members
Please Sign up or sign in to vote.
2.87/5 (4 votes)
See more:
i write javascript function
function Shape()
    var lbl1=document.getElementById("<%= Label3.ClientID%>");   
    var ddshap=document.getElementById("<%= ddshpe.ClientID%>");
       lbl1.innerHTML='Length of sample in cm';
       document.getElementById("rectangular").style.display = '';
       lbl1.innerHTML='Diameter of sample in cm';
       document.getElementById("rectangular").style.display = 'none';

and set it to dropdowanlist
<asp:DropDownList ID="ddshpe" runat="server" Height="22px" onchange="Shape();" 

it work fine after browse and dropdowan iteam change but when i select iteam from code its not working
protected void Page_Load(object sender, EventArgs e)
   ddshpe.Items.FindByText("Cylindrical").Selected = true;

tabulation corrected
Updated 5-May-14 5:07am
Kornfeld Eliyahu Peter 5-May-14 7:40am
Can you open debug window in the browser after it's 'not working' and see if there is a message for you?
Kornfeld Eliyahu Peter 5-May-14 7:40am
I copied you code into a VS project and it's seems to work fine...Maybe there is an other part of your code where the problem is?
dhiraj mane 5-May-14 7:48am
i select "Cylindrical" from ddshape at page load...because i select it then document.getElementById("rectangular").style.display = 'none'; this control in displayed which is script function is not working when i DropDownList select change @ page load

Selecting the default value on the server side will not affect the client side. Switch forth back the selection at the client and you will see that the JavaScript code is just fine...
You have to synchronize your display with your original selection, for that add a line to hide 'rectangular' in the Page_Load method...
Do NOT use 'rectangular'.Visible = false, that will prevent the rendering of 'rectangular'...
Replace '==' with '='. Your '==' would throw interpreter's exception which propagates and id silently handled in the browser, not allowing to interpret next line. Run your Javascript code under the debugger, check up id values. You can also view the resulting HTML and Javascript code in browser, by looking at "View Page Source" (or something like that), and, in particular, compare id values in script and HTML.

King Fisher 5-May-14 8:13am
hi sir,
How do i Debug Javascript and Jquery Scripts? Do i need any tool ?

Sanket Saxena 5-May-14 8:44am
Use firebug to debug your script and check console if any error came.
King Fisher 5-May-14 8:48am
thank you,
Sanket Saxena 5-May-14 8:50am
Welcome :)
King Fisher 5-May-14 8:53am
i have that but how do i handle that ? any Reference Link
Sanket Saxena 5-May-14 8:55am
press F12 you will see the window open in your browser. There are all the links, console , script etc. use whatever you want to. :)
King Fisher 5-May-14 9:06am
Thank you ;)
Sanket Saxena 5-May-14 9:10am
welcome again buddy :)
I used Visual Studio as it; tried something else. You can debug it...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900