如何使用vb.net验证asp.net中的dropdownlist [英] how to validate dropdownlist in asp.net using vb.net

查看:99
本文介绍了如何使用vb.net验证asp.net中的dropdownlist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面上有一些字段以及按钮和几个文本框下拉列表,下拉列表是auto post = true,因为在页面加载和选择的索引更改时从数据库获取数据我想在按钮按下时验证保存,我不想将空值保存到DB我试过requirefield验证器验证但是autopost返回不工作



请帮助我



问候



Yogesh

i have some fields on the page along with button and couple of textbox dropdown list , drop down list are auto post= true because there are getting data from database on page load and selected index change i wants to validate while button press to save , i don't wants to save null values to DB i tried requiredfield validater to validate but autopost back not working

kindly help me on that

Regards

Yogesh

推荐答案

提供ValidationGroup您的下拉菜单以及您的RequiredField验证器



您可以通过此代码进行javascript验证:





Do provide ValidationGroup to your dropdown and also to your RequiredField Validator

You can go through this code for javascript validation :


function manageValidation()
{

Validate the Page:
// validate all the validation that are present in the page.

Page_ClientValidate();

Validate the Page having certain validation Group:
// validate all the validation that are present in the page with this validation group.

Page_ClientValidate('ValidationGroup');

Get Is the page valid:
// Check wheather the page is valid or not

var pageValidated = Page_IsValid;
 if (pageValidated)
{
// Write some custom messages like

alert('Thanks for signing up with us. we will send your password to respective mail account');

}
else
{

// Other messages..

}

Enable or disable any validation :

// disable a certion validation
// ValidatorEnable(Control Name, status)

ValidatorEnable('requiredvalidatorTxtLastName', false)

// Enable some validation.

ValidatorEnable('requiredvalidatorTxtUserName', true)

Force Validation:

// Attach a certion validation with the control

ValidatorHookupControl('txtUserName', 'requiredvalidatorTxtUserName')

// Validate a certain validation.

ValidatorValidate('requiredvalidatorTxtUserName')

}
 
Manual Validation :
If you want to make the validation false of the page for any customize javascript Code you can do it as follows.

function checkPoints(sender,args)
{
  if(document.getElementById('txtPoints').value == (parseInt(    document.getElementById('txtBasicPoint').value) * 2)
   {
     args.isValid = false;
    }
}


这篇关于如何使用vb.net验证asp.net中的dropdownlist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆