Access selected value from disabled dropdownlist - asp.net

when I am disable dropdownlist using js, and then I access from .cs page.
It gives o value even there is one item is selected..
I want to disable dropdownlist but at the same I want to access its selected value as well

You cant access the disabled items from Code behind.
Disabled form values will not be sent in post data.
Check this post
Disabled form fields not submitting data
If you need add some css techniques like opacity and do.

Try to add selected value of dropdown in hidden field, and access value from hidden field.

Related

Required Field Validator on RadioButton list

I have a radiobutton list that the items are dynamically filled. Now, I have a required field validator that works as expected (if I do a postback, it will ask me to select an item in the radiobuttonlist).
When I click on Next, I clear the radiobuttonlist, and dynamically fill it again with the next set of data. But now, the required field validator's message is already there asking me to select an item (without doing a postback).
Any ideas to make the required field validator message only become triggered if I do a postback?
Thanx
You should be able to disable the required field validator client side validation with the following:
ValidatorEnable($("#<%=ReqVal.ClientID%>")[0], false);
Replace the ReqVal with the id of your RequiredFieldValidator that you want to disable.

disabled dropdownlist does not keep selected value on postback

I'm getting a weird behavior with a dropdownlist when I trigger a postback.
If the dropdownlist is enabled, the selected value remains the same after a postback.
However, if the dropdownlist is disabled (via a javascript when user ticks a checkbox), then the selected value is reset to the first item in the list.
How come ?
you need to look up the value manually (probably store it in another field or so), and then set it yourself in the code behind. This is because if a control is disabled, the value would not be posted back to the sever.
Check out this question, and refer to the first answer by Pavan
how to get selected value of Disabled dropdown in c#
If you are trying to read the value of 2nd dropdown (disabled one) at
server, you will never be able to read the updated value, becuase data
in disabled controls will not be posted back to server from client

Get Control Value From Web User Control

Lets say I have three DropDownList controls in a web user control and they depend on each other.
Categories
Brands
Products
Explanation:
After I choose a category from Categories dropdown list, related brands are loaded in Brands DropDownList and same happens when I choose specific brand and they are all located in a web user control since I am using it too much on different pages, I don't want to copy and paste the same code on all the pages.
Problem: The pages can contain a GridView and DataSource control which needs an additional Where parameter to fetch all the data needed in and that parameter could depend on selected product within the Products DropDownList control.
Question: So how can I get that Selected Product Value from Products DropDownList to bind it to SQLDataSource or any other DataSource control.
My Thoughts: I belive I can solve this problem in the ways following.
I can use static variable which is updated once Products selected. That field variable could be public so everyone can reach it
Selected Products DropDownList can create a QueryString Field for me to grap the selected value.
In the same way, the dropdownlist can create a Session variable on the fly and I can fetch the value
It can create a hidden field maybe.
But: Well those are some of my thoughts but I found them so naive to implement. I need something elegant and satisfying to solve this problem. It should be something like a gateway from the Web User Control to outside world.
Maybe a separate class or a Property can help me in the gateway solution.
Anyways, I am waiting for your answers.
If I'm understanding the question correctly:
You can add a property to the user control that exposes the products DDL selected value.
You can also add and raise an event from the user control that fires when the products DDL selected value changes. Creating a custom event argument that contains the product value, allows it to get passed directly to the event handler.
Then your pages can handle the event raised by the user control, have the product value, and bind the grid.
You could bind the DropDownList.SelectedIndexChanged events to the same function, and test the SelectedValue properties of each DropDownList. If their SelectedValues are valid, bind the grid to your DataSource.
I've done this in the past when I needed users to input a certain amount of data before I could query the database. I set the Hidden property on my GridView if the DropDownLists weren't valid, and reset it when they were properly bound.

Accessing a Dropdown from child window

I have on server control(dropdown) and One button.user can select some values in dropdown and click button.I have to show a pop-up.In this pop-up I have show data based upon value selected in dropdown.How to access a dropdown in codebehind of pop-up screen.I am loading a .aspx in pop-up using javascript.
Why not just pass the selected value of the dropdownlist as a querystring parameter to the popup page?
That's the way i'd do it.
If you dont want to do it that way, you can access the parent window by using window.opener.document.
So something like:
window.opener.document.getElementById('yourDDLId').value;
Still i'd recommend passing through as querystring param. Simple and easy.

DropDownList Setting Default Value

How should I get a value displayed in the DropDownList when redirected through a cancel buttton. The value in the page where cancel button is there in a TextBox should be caught in the DropDownList.
This DropDownList has SelectedIndexChanged event also fired for which on selection of a country in the list we get a ListView displayed in the same page. In that ListView we have an add button which will redirect us to another page called addcountry in which we have few controls. In those controls one TextBox I am getting value through QueryString in an enabled False state. Now again I need that value displayed in the DropDownList when I click cancel button.
How can I solve this problem?
Using $_POST and $_GET Variables you should be able to retreive almost any value from a form and put it in the right place on a new page, this right place can be one of your drop down list element...
To make absolutly sure your Cancel Button will send the good value to the right page put it in an independant form that has your new page (where you have yout dropdown list) as its action, and in this seperate form put an hidden field that holds the specific value you wanna see in this dd list ...
Hope I am clear but starting with your very "fuzzy" and blur question It is hard to help you.

Resources