regarding drpo down list

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: regarding drpo down list

 
0
  #11
Dec 31st, 2008
Try this without a postback. This works with javascript to do it on the client, not on the server:

  1. <asp:DropDownList ID="ddldept" onchange="chkChange(this);" runat="server" Style="z-index: 131; left: 242px; position: absolute; top: 153px">
  2. <asp:ListItem>Solutions</asp:ListItem>
  3. <asp:ListItem>SA</asp:ListItem>
  4. <asp:ListItem>Training</asp:ListItem>
  5. <asp:ListItem>HR</asp:ListItem>
  6. <asp:ListItem>Finance</asp:ListItem>
  7. <asp:ListItem>Documentation</asp:ListItem>
  8. <asp:ListItem>Quality</asp:ListItem>
  9. <asp:ListItem>NewDepartment</asp:ListItem>
  10. </asp:DropDownList>
  11. <asp:TextBox ID="TextBox1" runat="server" style="display: none;" />
  12. <script type="text/javascript">
  13. function chkChange(ddl)
  14. {
  15. var textbox = document.getElementById("<%= TextBox1.ClientID %>");
  16.  
  17. if (ddl.options[ddl.selectedIndex].value == "NewDepartment")
  18. {
  19. textbox.style.display = "block";
  20. }
  21. else
  22. {
  23. textbox.style.display = "none";
  24. }
  25. }
  26. </script>

By changing the options, it will do a check to see if the value selected is "NewDepartment". If it is, the textbox will be shown. if not, it will be hidden.
I answer pm's.
I answer questions.
I answer quickly.
I answer.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 37
Reputation: kodingkarthik is an unknown quantity at this point 
Solved Threads: 0
kodingkarthik kodingkarthik is offline Offline
Light Poster

Re: regarding drpo down list

 
0
  #12
Jan 1st, 2009
Happy New Year 2009!!!!!!!!!!!!!!!
Thanks for your reply to my query but if i am using this code it is giving me an error at onchange=chkChange(this) saying that it(onchange()) is not a valid attribute can you suggest me any changes?

Thanks in advance,
Karthik.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 104
Reputation: Aneesh_Argent is an unknown quantity at this point 
Solved Threads: 18
Aneesh_Argent Aneesh_Argent is offline Offline
Junior Poster

Re: regarding drpo down list

 
0
  #13
Jan 1st, 2009
Happy New Year 2009

"onchange() is not a valid attribute" is just a warning message. That's because you're using a webcontrol, which doesn't have an onchange
method. Visual Studio is letting you know that OnChange isn't a valid event for the DropDownList control. However, it is a valid event for an HTML input element and will be passed through to the rendered HTML and should work as expected. But if the warning bothers you, you can use ddldept.Attributes.Add("onchange", "chkChange(this);") in your code behind page load event , to set the client side attribute (and delete the onchange attrbute from your source).

In short the above code (of SheSaidImaPregy) will work despite the warnings that you metioned.
Last edited by Aneesh_Argent; Jan 1st, 2009 at 3:07 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 37
Reputation: kodingkarthik is an unknown quantity at this point 
Solved Threads: 0
kodingkarthik kodingkarthik is offline Offline
Light Poster

Re: regarding drpo down list

 
0
  #14
Jan 1st, 2009
Thanks for your help but i am getting an IE Script error window saying tht would you like to continue with Yes/no Buttons
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 104
Reputation: Aneesh_Argent is an unknown quantity at this point 
Solved Threads: 18
Aneesh_Argent Aneesh_Argent is offline Offline
Junior Poster

Re: regarding drpo down list

 
0
  #15
Jan 1st, 2009
Can u post ur complete code(.aspx). Or is it exactly the same as above(I suppose not coz its working fine for me in IE and FF)
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 37
Reputation: kodingkarthik is an unknown quantity at this point 
Solved Threads: 0
kodingkarthik kodingkarthik is offline Offline
Light Poster

Re: regarding drpo down list

 
0
  #16
Jan 1st, 2009
Here is my code:
  1. <asp:DropDownList ID="ddldept" OnChange="chkChange(this);" runat="server" Style="z-index: 118; left: 242px; position: absolute;
  2. top: 153px">
  3. <asp:ListItem>Solutions</asp:ListItem>
  4. <asp:ListItem>SA</asp:ListItem>
  5. <asp:ListItem>Training</asp:ListItem>
  6. <asp:ListItem>HR</asp:ListItem>
  7. <asp:ListItem>Finance</asp:ListItem>
  8. <asp:ListItem>Documentation</asp:ListItem>
  9. <asp:ListItem>Quality</asp:ListItem>
  10. <asp:ListItem>NewDepartment</asp:ListItem>
  11. </asp:DropDownList>
  12. <asp:TextBox ID="txtdept" runat="server" Style="z-index: 127; left: 361px; position: absolute;
  13. top: 153px" Width="113px" Visible="False"></asp:TextBox>
  14. <script type="text/javascript">
  15. function chkChange(ddl)
  16. {
  17. var textbox = document.getElementById("<%= txtdept.ClientID %>");
  18. if (ddl.options[ddl.selectedIndex].value == "NewDepartment")
  19. {
  20. textbox.style.display = "block";
  21. }
  22. else
  23. {
  24. textbox.style.display = "none";
  25. }
  26. }
  27. </script>
  28. <asp:TextBox ID="txtdesig" runat="server" Style="z-index: 119; left: 590px; position: absolute;
  29. top: 149px"></asp:TextBox>
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 104
Reputation: Aneesh_Argent is an unknown quantity at this point 
Solved Threads: 18
Aneesh_Argent Aneesh_Argent is offline Offline
Junior Poster

Re: regarding drpo down list

 
0
  #17
Jan 1st, 2009
Ok just replace your textbox with this


<asp:TextBox ID="txtdept" runat="server" Style="z-index: 127; left: 361px; position: absolute;
top: 153px; display:none" Width="113px"></asp:TextBox>
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: regarding drpo down list

 
0
  #18
Jan 1st, 2009
Aneesh_Argent is right, you need to replace the Textbox, or remove the "Visible='False'" property. The one thing you will need to learn about the visibility property of these web controls is that if it is "False", it will not be rendered on the page. You were receiving an error because your textbox didn't exist on the client's computer (browser), since it was never rendered from the server. By removing the Visible="False", and adding in your Style attribute the "display: none;", you will have the desired output, and would not require a postback to the server which will save time for a simple task.

Also, by coding this way, you will be seeing a lot of "warning" messages. If you wish to avoid the warning messages, use Aneesh's suggestion and manually attach the event from the code-behind, or inline if that is what you are using. (Code-behind has the code file associtated with it: default.aspx --> default.aspx.cs || Inline coding has the code on your same page: default.aspx). Attach the event just how he suggested. You will avoid these warnings, but it's a lot of extra code and can be more difficult to change in the future as it brings the design and business layers together.
Last edited by SheSaidImaPregy; Jan 1st, 2009 at 10:29 am.
I answer pm's.
I answer questions.
I answer quickly.
I answer.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 37
Reputation: kodingkarthik is an unknown quantity at this point 
Solved Threads: 0
kodingkarthik kodingkarthik is offline Offline
Light Poster

Re: regarding drpo down list

 
0
  #19
Jan 1st, 2009
Thanks to both of you but if i do like that i am not getting my desired o/p
My requirement is
If the user selects NewDepartment in the combobox then only the text box should be visible until then it is should be hidden and later when the textbox is displayed then the cursor should be in the textbox. if the user enters a value into the textbox it must be captured and populated into the combo box dynamically and also for that particular employee the value for the newdepartment must be saved into the database.

thanks for u all,
Karthik.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: regarding drpo down list

 
0
  #20
Jan 1st, 2009
In javascript (the script tags below your dropdownlist), you can set focus to an element by first grabbing the element (document.getElementById("id")) and applying ".focus()". Becareful of this, it will throw an error if your element trying to be focused doesn't exist or is hidden. To add an option to the dropdownlist, you first grab it like above, then add the attributes ".options" and then ".add". An example is below:

  1. document.getElementById("<%= ddldept.ClientID %>").options.add(new Option(index, "value", "text"));
Last edited by SheSaidImaPregy; Jan 1st, 2009 at 5:47 pm.
I answer pm's.
I answer questions.
I answer quickly.
I answer.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC