Total Page Preview:   000000000570

What is required field validator in ASP.NET in English and Hindi

 

Required field validator in ASP.NET in English

A RequiredFieldValidator is an ASP.NET validation control that can be used to validate whether a user has entered a value in a required field. The control ensures that the user fills out the required field before submitting the form.
Here is an example of how to use a RequiredFieldValidator control in ASP.NET:
1-First, add a TextBox control to your ASP.NET web form. You can do this either by dragging and dropping a TextBox control from the toolbox onto the design surface, or by adding the following code to your .aspx file:
2-Next, add a RequiredFieldValidator control to your web form. You can do this either by dragging and dropping a RequiredFieldValidator control from the toolbox onto the design surface, or by adding the following code to your .aspx file:
 
In this code, we have added a RequiredFieldValidator control and set its ControlToValidate property to the ID of the TextBox control that we added in step 1. We have also set the ErrorMessage property to display a message if the user does not enter a value in the TextBox control.
 
3-Finally, add a Button control to your web form. You can do this either by dragging and dropping a Button control from the toolbox onto the design surface, or by adding the following code to your .aspx file:

4-In your C# code-behind file, you can handle the Button control's Click event to check whether the page is valid or not. For example:

In this example, we have handled the Click event of the Button control and checked whether the page is valid or not. The Page.IsValid property returns true if all the validation controls on the page are valid.
That's it! This is a basic example of how to use a RequiredFieldValidator control in ASP.NET using C#. You can customize the appearance and behavior of the RequiredFieldValidator control using various properties and styles.
 
 
 
Required field validator in ASP.NET in Hindi
 
RequiredFieldValidator ek ASP.NET validation control hai jo ye ensure karta hai ki user form submit karne se pehle ek required field mai value enter karein. Agar user ne required field mai koi value enter nahi ki hai, to RequiredFieldValidator control validation fail kar deta hai aur user ko error message show karta hai.
Yaha ek example diya gaya hai ki kaise hum RequiredFieldValidator control ko ASP.NET mai use kar sakte hai:
1-Sabse pehle, apne ASP.NET web form mai ek TextBox control ko add karein. Aap ise ya to toolbox se TextBox control ko drag and drop karke design surface pe add kar sakte hai ya phir apne .aspx file mai ye code add karke bhi kar sakte hai:
 
2-Ab, RequiredFieldValidator control ko apne web form mai add karein. Aap ise ya to toolbox se RequiredFieldValidator control ko drag and drop karke design surface pe add kar sakte hai ya phir apne .aspx file mai ye code add karke bhi kar sakte hai:
 
Is code mai, humne RequiredFieldValidator control ko add kiya hai aur uske ControlToValidate property ko TextBox1 control ke ID se set kiya hai. ErrorMessage property mai humne ek error message bhi set kiya hai, jo show hoga agar user ne TextBox control mai koi value enter nahi ki hai.
3-Ab, apne web form mai ek Button control ko add karein. Aap ise ya to toolbox se Button control ko drag and drop karke design surface pe add kar sakte hai ya phir apne .aspx file mai ye code add karke bhi kar sakte hai:
 
4-Apne C# code-behind file mai, aap Button control ke Click event ko handle kar sakte hai aur check kar sakte hai ki page valid hai ya nahi. Jaise ki is example mai:
 
Is example mai, humne Button control ke Click event ko handle kiya hai aur check kiya hai ki page valid hai ya nahi. Page.IsValid property true return karega agar saari validation controls valid hai.
Ye ek basic example hai ki kaise hum RequiredFieldValidator control ko ASP.NET mai use kar sakte hai. Aap RequiredFieldValidator control ke appearance aur behavior ko various properties aur styles ka use karke customize kar sakte hai.

 

 

 

Thank You

About Author

Brijesh Kumar

Database Developer

I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall and Database Migration On-Premise to Azure Cloud.
LinkedIn : https://www.linkedin.com



Comments


                           
                           

                           

                           

Facebook User: