Tuesday, December 16, 2008

Cannot have multiple items selected in a DropDownList

This problem occurs when we try to select more than one item in the drop down at the same time. Also however the most common reason I found this to happen is that the same list item is added to multiple drop downs. Then we to select different values in these different drop downs where same list item was added. Ideally in order to avoid this, we should add new list items to each drop downs. We should carry list item added from one drop down to another
Sample code:
The following code causes error

//bind first dropdown
ListItem listCommon = new ListItem("Please Select One", "0");
ddlFirstDropDown.Items.Clear();
ddlFirstDropDown.Items.Add(listCommon);
ddlFirstDropDown.Items.Add(remaining items);

//bind second dropdown
ddlSecondDropDown.Items.Clear();
ddlSecondDropDown.Items.Add(listCommon);

ddlSecondDropDown.Items.Add(remaining items);

Fix:

//bind first dropdown
ListItem listCommon = new ListItem("Please Select One", "0");
ddlFirstDropDown.Items.Clear();

ddlFirstDropDown.Items.Add(listCommon);
ddlFirstDropDown.Items.Add(remaining items);

//bind second dropdown
ListItem listNewItem= new ListItem("Please Select One", "0");

ddlSecondDropDown.Items.Clear();
ddlSecondDropDown.Items.Add(listNewItem);
ddlSecondDropDown.Items.Add(remaining items);


And secondly always use the following code to select the particular value from drop down
ddlSecondDropDown.SelectedIndex = ddlSecondDropDown.Items.IndexOf (ddlSecondDropDown.Items.FindByValue(string value)));

Never use ddlSecondDropDown.SelectedValue or ddlSecondDropDown.SelectedItem for selecting a particular value from the drop down.


Keeping the above two things in mind should solve the problem.


Cheers

Monday, December 15, 2008

Cannot Use Leading..... to exit Top Directory

hey all,

We get this error message, when ever we are migrating an application from .Net frame work 1.1 to 2.0. The main cause of this issue is, in our 1.1 code we refer to urls using ".." syntax, to move to parent directory. This is not allowed in 2.0 frame work. So in order to make the code work in 2.0, we need to convert all the urls in the format using "~/" or "/" directly.
Eg: if url ="../images/image.gif" is the code present in 1.1 framework
then this image url needs to changed to url = "~/images/image.gif" for the code base to work with .Net framework 2.0.

Happy Coding

Wednesday, December 3, 2008

My Blog Visitors

free counters

Shows count of the number of visitors visiting my Blog from different countries.

Page Load happens twice in ASP.Net

We are working on a project, in which we are suppose to call a ASPX page from a HTML page. We have a Button in the HTML page, in which we are using javascript to make a call to redirect to ASPX page. We observed that when we try to call the ASPX page, the page load is happening twice.

This was because the method in javascript was not returning a false value on button click event. So when we were redirecting a page load was fired and again since the method has not returned false, once more the page load was getting executed.

So if we return a false from the button click event, then the page load is happening only once.

Hope this solves the issue that most of us are facing of page load being executed twice.