473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dropdownlist's enableviewstate not workin

112 100+
Hi there..

This problem is stopping me from winding up my project. I have a webform where there is a pop-up page that populates one text box and 2 dropdowns. And I also have a checkbox list that does a postback. Whenever the checkboxlist does a postback, one of the dropdownlist's value is reset. It happens with only one dropdown list. The text box and the other dropdownlist retain their value. I have put enableviewstate = true at both the page level and control level.

Somebody please help me.....what is the reason for this strange behavior.
Any response is highly appreciated...

thank you
Jan 21 '10 #1
6 3975
user1980
112 100+
thank you for your response.......it did not help me much though...
please find my code below....

Expand|Select|Wrap|Line Numbers
  1. <asp:DropDownList ID="hsstate" runat="server"
  2.   DataSourceID="SqlDataSource5" DataTextField="StateName"
  3.   DataValueField="Num" EnableViewState="true" AppendDataBoundItems="true">
  4.     <asp:ListItem Value="" Text="---  Please select a state  ---" />
  5. </asp:DropDownList>
  6. <asp:SqlDataSource ID="SqlDataSource5" runat="server"
  7.   ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
  8.   SelectCommand="SELECT Num, StateName FROM State WHERE (Num < 63) OR (Num = 76) ORDER BY [StateName]">
  9. </asp:SqlDataSource>
  10. <asp:RequiredFieldValidator ID="RequiredFieldValidator_hsstate" ControlToValidate="hsstate" runat="server" ErrorMessage="Please select your highschool state"
  11.   Enabled="false" Display="Dynamic">*</asp:RequiredFieldValidator>


javascript that populates the dropdown...

Expand|Select|Wrap|Line Numbers
  1. function pick(symbol) {
  2.    var state,city,i;
  3.       fullname = symbol.split(",");
  4. city = fullname[0];
  5.  
  6.    state = fullname[1];
  7.  
  8.  
  9.   if (window.opener && !window.opener.closed)
  10.              window.opener.document.form2.hscity.value = city;
  11.  
  12.  
  13.         for (i=0;i<window.opener.document.getElementById("hsstate").length;i++ )
  14.         {
  15.  
  16.             if (window.opener.document.getElementById("hsstate").options[i].text = state )
  17.             {
  18.              window.opener.document.getElementById("hsstate").selectedIndex = i;
  19.              break;
  20.             }
  21.         }
  22.  
  23.           window.close();
  24.  
  25.     }
I am using a drop-down pulling its data from a table...and the data is binding properly after every page load..it is the selected value that disappears..I mean the selectedindex,say 5, is reset after page load..whatever value the pop-up page selects is present till the page postsback...and after postback it is reset to "Please select the value".


thank you for your time..
Jan 22 '10 #2
Frinavale
9,735 Expert Mod 8TB
User1980,

The DropDownList that is working correctly...is it bound to using an SqlDataSource as well?

-Frinny
Jan 25 '10 #3
user1980
112 100+
thank you for the response....yeah..the drop down is binding correctly. I have found what the problem is but unable to fix it....
Expand|Select|Wrap|Line Numbers
  1.  
  2.    1. function pick(symbol) {
  3.    2.    var state,city,i;
  4.    3.       fullname = symbol.split(",");
  5.    4. city = fullname[0];
  6.    5. state = fullname[1];
  7.    7.    
  8.    9.   if (window.opener && !window.opener.closed)
  9.   10.              window.opener.document.form2.hscity.value = city;
  10.   11.  
  11.   13.         for (i=0;i<window.opener.document.getElementById("hsstate").length;i++ )
  12.   14.         {
  13.   15.             if (window.opener.document.getElementById("hsstate").options[i].text = state )
  14.   17.             {
  15.                 window.opener.document.getElementById("hsstate").selectedIndex = i;
  16.   19.              break;
  17.   20.             }
  18.   21.         }
  19.   22.  
  20.   23.           window.close();
  21.   24.  
  22.   25.     }
  23.  
  24.  
in the above javascript, I have found that the selectedindex is always set to 0..ie; when i = 0, the if condition works and breaks and the selectedindex is always set 0, that is the reason my main page is not able to preserve the value and resets back after every postback.
I have no clue why the if condition is true only when i = 0....it is supposed to be true when the original dropdown's text is equal to the required text

I assume the way I am trying to select the dropdown using this script is wrong...
Jan 25 '10 #4
user1980
112 100+
hello..i have temporarily solved my problem by replacing the dropdown with a text box..but I have one more problem...

in my pop-up window, the dataview has names that contain " 's " in their names like Byte's, etc....so when I am using my javascript to select this name, the javascript breaks at " 's ".
Ex: pick(Byte
where as it is expected to do pick(Bytes's, testcity)
How can I do this???

thank you for your time
Jan 25 '10 #5
Frinavale
9,735 Expert Mod 8TB
See the comments:

Expand|Select|Wrap|Line Numbers
  1. function pick(symbol) {
  2.   var state,city,i;
  3.   fullname = symbol.split(",");
  4.  
  5. //making sure that there are 2 elements in the fullname array
  6. //before trying to access the elements.
  7.   if(fullname.length==2){
  8.     city = fullname[0];
  9.     state = fullname[1];
  10.   }
  11.  
  12. //I added {} to the following if:  
  13.   if (window.opener && !window.opener.closed)
  14. {
  15.  
  16. //Accessing document.form2 directly is not a good idea.
  17. //Instead use the document.getElementByID() method 
  18. //to access the element "hscity"
  19. //    window.opener.document.form2.hscity.value = city; 
  20.  
  21. //Added the check to make sure hscity exists 
  22. if(window.opener.document.getElementById("hscity") )
  23. {
  24.   window.opener.document.getElementById("hscity").value = city =;
  25. }
  26.  
  27. //I'm assuming that hsstate is the DropDownList
  28. //a DropDownList is rendered as an HTML <select> element
  29. //this element has a bunch of <option> elements within it 
  30. //you have to access the htmlSelectElement.options property 
  31. //to access the "options" 
  32.  
  33. if(window.opener.document.getElementById("hsstate"))
  34. {
  35.  
  36. //Notice that I added .options....
  37.   for (i=0;i<window.opener.document.getElementById("hsstate").options.length;i++ )
  38.   {
  39.     if (window.opener.document.getElementById("hsstate").options[i].text = state )
  40.     {
  41.       window.opener.document.getElementById("hsstate").selectedIndex = i;
  42.       break;
  43.     }
  44.   }
  45. }//close check if hsstate exists
  46.  
  47. //Following line is your code..not sure why you're closing the window.
  48.   window.close();
  49. }//close check if window opener is opened
  50.  
  51. }
Jan 25 '10 #6
Frinavale
9,735 Expert Mod 8TB
I never saw any code that would have a problem with the apostrophe (')...

Usually this will mess things up if you are defining strings using apostrophes instead of double quotes....consider using double quotes instead of single quotes (aka apostrophes) where ever this is a problem.

-Frinny
Jan 25 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
4
by: Iain Kirk | last post by:
Being a bit of a novice any help or pointers would be appreciated. I am building a web page that populates a DropDowList from a table in SQL, for testing purposes i have a simple page that...
5
by: DC Gringo | last post by:
I have a dropdownlist that, upon form submission, I'd like to maintain the selected value when I get my result...how do I do that? <asp:dropdownlist Font-Size="8" id="ddlCommunities"...
0
by: Ashish Sharma | last post by:
I have a drop down list inside a data list on a form like this : <asp:DataList ID="DataList1" runat="server" EnableViewState="False"> <ItemTemplate> <asp:Label ID="lblname" Runat="server"...
1
by: Paul L | last post by:
Hi, I have an issue with the OnSelectedIndexChanged event not firing for a DropDownList control which is in the ItemTemplate of a DataList. I have made an exact copy of the DropDownList control,...
1
by: Michael Kolias | last post by:
Hi everybody, I am having a problem getting the selected value of a drop down list that is populated dynamically inside a datagrid control. When I try to access the selected item on the...
0
by: fwirtanen | last post by:
I am building a custom composite control consisting of two drop downs, with parent/child dependancy. The child dropdownlist is updated through client callback when the parent index changes. ...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
5
by: revbart | last post by:
Yep, that's me. I'll bet I've read a hundred articles somewhere or another, but I just can't get the thing to work. I'm working on a custom solution. One of the major UIs includes a calendar-style...
0
by: stevem2112 | last post by:
I have a datagrid with 2 Template columns. One column has DropDownLists and the other has Textboxes. I bind each DDL in the ItemCreated event. This datagrid is inside a UserControl that is inside...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.