I have an asp.net dropDownList listing hours and minutes of the day. I want the time chos开发者_运维知识库en to be shown in a texbox. Can this be done without making a postback?
Thank you DovAdd an onChange to the drop down and use java script to detect the dropdown selection and write to the textbox.
you can use an update panel from ajax control toolkit, if you can use ajax.
It actually creates a postback but partially so end user point of view, seems no postback occures; and your point of view, only the elements in update panel is affected by the postback.
If you don't mind using JavaScript and more specifically jQuery you can set the time client side as shown in this simple example:
HTML:
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
function setTime(){
var hours = $(".hours").val();
var mins = $(".minutes").val();
$(".time").val(hours + ":" + mins );
};
$(".hours").change(setTime);
$(".minutes").change(setTime);
// call setTime for first view
setTime();
});
</script>
</head>
<body>
<input type="text" class="time" />
<select class="hours">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<select class="minutes">
<option>15</option>
<option>30</option>
<option>45</option>
</select>
</body>
There is a working example here
In the microsoft Ajax control toolkit there's a ComboBox which gives DropDownList and TextBox functions enabling choosing from the ComboBox or writing directly like a TextBox. Also enables limitting independent writing only to items in the ComboBox or entering nonexisting items.
精彩评论