How to make ajax auto-complete compulsory? - c#

I want to force the user to select from the auto-complete options.
NB: I do not want to use a drop down menu.

Try using this
var isItemSelected = false;
//Handler for AutoCompleter OnClientItemSelected event
function onItemSelected() {
isItemSelected = true;
}
//Handler for textbox blur event
function checkItemSelected(myTextBox) {
if (!isItemSelected) {
alert("Please select item from the list only!");
myTextBox.focus();
}
else {
//reset isItemSelected
isItemSelected = false;
}
}
And then throw this in the Textbox:
onblur="checkItemSelected(this)"

Well i have this forum for the references .
Forum,
You'll need to use the select and focus options to support this.
Fiddle example
focus: function( event, ui ) {
$( "#tags" ).val( ui.item.label );
return false;
},

Related

Prevent Key Event on DevExress ASP.NET MVC SpinEdit

In a form, I have a spin edit control like this:
formLayoutSettings.Items.Add(i =>
{
i.FieldName = "FieldA";
i.NestedExtension().SpinEdit(s =>
{
s.Properties.MinValue = 1;
s.Properties.MaxValue = 9999999999999;
s.Properties.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.ImageWithTooltip;
s.Properties.ClientInstanceName = "seFieldA";
s.Properties.Increment = 10;
s.ShowModelErrors = true;
s.Width = Unit.Percentage(100);
s.Properties.AllowMouseWheel = false;
s.Properties.ClientSideEvents.KeyDown = "OnFieldAKeyDown"; // This is the event heandeler
});
});
And the function:
function OnFieldAKeyDown(s, e) {
if (e.htmlEvent.keyCode == 38 || e.htmlEvent.keyCode == 40) {
ASPxClientUtils.PreventEventAndBubble(e.htmlEvent); // this doesn't work
ASPxClientUtils.PreventEvent(e.htmlEvent); // this either
}
}
My aim is to prevent the spin edit control value from changing when the user presses the Up key or Down keys. When I debug this, the if test inside the OnFieldAKeyDown works but PreventEventAndBubble and PreventEvent fails miserably. Also, is there any other way to do this with jquery ??
Thanks.
AFAIK, there is a workaround to prevent a user incrementing/decrementing SpinEdit value using up/down arrow keys without using PreventEvent or PreventEventAndBubble. When there's no public method available on JS side, you can try restore SpinEdit previous value in KeyDown event handler like this:
<script type="text/javascript">
function OnFieldAKeyDown(s, e) {
if (e.htmlEvent.keyCode == 38 || e.htmlEvent.keyCode == 40) {
// check if ASPxClientSpinEdit exists
if (typeof ASPxClientSpinEdit !== "undefined") {
ASPxClientSpinEdit.prototype.OnPageOrArrowKeyDown = function() {
// when user tries either increment or decrement, it returns last value instead
if (s.GetValue() != s.lastChangedValue) {
s.SetValue(s.lastChangedValue);
}
// if spinedit's minimum & maximum values also affected, set current limit
else {
s.maxValue = ASPxClientSpinEdit.MaxValue;
s.minValue = ASPxClientSpinEdit.MinValue;
}
}
}
}
}
</script>
Combine this function with jQuery may possible, any suggestions welcome.
Reference: https://www.devexpress.com/Support/Center/Question/Details/Q254514

Disable specific items in a CheckboxList

I am running through a set of data, which will populate a CheckBoxList. I want to display all the items in the list but certain ones will be disabled as they don't qualify (their status equals Inactive). How do I set an item to disabled (Enabled = false) in the code behind like this?
if (node.SelectSingleNode("Status") == "Inactive")
{
customerList.Items.Add(new ListItem(displayName, displayValue)); // DISABLED
}
else
{
customerList.Items.Add(new ListItem(displayName, displayValue)); // ENABLED
}
if (node.SelectSingleNode("Status") == "Inactive")
{
customerList.Items.Add(new ListItem{Name=displayName, Value= displayValue, Enabled= false}); // DISABLED
}
else
{
customerList.Items.Add(new ListItem(displayName, displayValue)); // ENABLED
}`
Haven't tried it but this may work:
customerList.Items.Add(new ListItem(displayName, displayValue)); // DISABLED
ListItem li = customerList.Items.FindByValue(displayValue);
li.Enabled = false;
UPDATED to use FindByValue

How to handle keydown Event in asp.net Textbox?

I have a textbox in web form(asp.net). when user already keyin data, then they will press Enter key, so that the data will be update to database.
Is there any way possible to perform this?
function InitTextBox() {
//var _txt = $('#<%= txt.ClientID%>'); or
var _txt = $('input:[id*="txtId"]');
if (_txt.length < 1) return;
_txt.get(0).autocomplete = 'off';
_txt.on('keydown', function (evt) {
var _self = $(this);
event = evt ? evt : window.event;
if (event.keyCode == 13) {
if ($.browser.msie)
{ event.cancelBubble = true; event.returnValue = false; }
else { event.preventDefault(); }
if (_self.val().length > 0 && _self.val().match(/^\s*$/) == null)
__doPostBack(_self.attr('name'), '');
}
});
}
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(InitTextBox);
And set autopostback for textbox to false, please
Dino Esposito had wrote about this a while back. You wouldn't necessarily need a custom control, but can use his JavaScript.
If you have a control wrapped around a Panel, and you have the DefaultButtonID property set, the panel will trigger a postback on enter too by clicking the desired button specified by the ID. That's another way.

How can I Enable And Disable Ajax Rating Control on CheckBox Check In JavaScript

How can I Enable And Disable Ajax Rating Control on CheckBox Check In JavaScript??
Currently I'm enabling and disabling Textbox on CheckBox Check In JavaScript in this way
function Del_Checked(DelEnabled) {
var DelStatus = document.getElementById("<%= cb_foodDelStatus.ClientID %>");
if (DelStatus.checked === true) {
document.getElementById("<%= tb_DelTime.ClientID %>").disabled = false;
}
else {
document.getElementById("<%= tb_DelTime.ClientID %>").disabled = true;
}
}
onclick = "Del_Checked(this.checked);" // Added this to Checkbox
you can set the Read only attribute of Ajax Rating control through jquery as:
if($("#checkboxID").is(':checked'))
$find("RatingBehaviourID").set_ReadOnly(true);

How to handle Yes No dialog that was pop-up using Javascript on button click

I am having an update button on my from on clicking update i would like to prompt the user as Do you want to delimit the record with Yes and No buttons. If the user clicks on Yes i would like to execute the code which can delimit the record if not just update the record.
My sample code
protected void btnUpdate1_Click(object sender, EventArgs e)
{
EmpID = Convert.ToInt32(HiddenField1.Value);
if (ID == 2)
{
oEmployeePersonalData.EmpID = EmpID;
oEmployeePersonalData.PhoneNumberTypeID = ddlPhoneType.SelectedValue;
oEmployeePersonalData.PhoneNumber = Convert.ToInt64(txtph1.Text);
oEmployeePersonalData.EndDate = DateTime.Today.AddDays(-1);
//As per my requirement if i click on yes i would like to execute this code
if (oEmployeePersonalData.PhoneDetailUpdate())
{
}
// If No different code
if(confirm("Would you like to delimit the record"))
{
//Delimit record code or return true;
}
else
{
return false;
}
Add following javascript function in the header of the page
<script type="text/javascript">
function update() {
var result = confirm("Do you want to delimit the record?")
if (result) {
}
else {
return false;
}
}
</script>
and then attach the event to button
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" OnClientClick="return update();"/>
var ans = confirm("Do you want to delimit the record?")
if (ans){
//clicked on yes
}
else{
return false;
}

Categories