Click here to Skip to main content
15,889,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have taken createuserwizard control in my asp.net page. Actually the page is postback even the textboxes are empty in createuserwizard, when i press "create user" button.

I don't want the page to postback if any textbox is empty in createuserwizard..

Can you please tell me how to do this?? I googled but nothing found..
Posted
Comments
TrushnaK 31-May-14 3:11am    
Use requiredfield validator or do some scripting for validating your textbox.

If you return false from your client click function then postback will not happen.

ASP.NET
<asp:button text="Create User" ID="btnUser" runat="server" onclick="btnUser_Click"" onclientclick="validateForm()" />


JavaScript
function validateForm() {
            var x = document.getElementById("txtUserName").value;

            document.getElementById("txtUserName").value="hello";

            if (x == null || x == "") {
             
                  //Code for error message what do you want.
                return false;
            }
        }
 
Share this answer
 
v2
Comments
Harpreet_125 31-May-14 3:14am    
i also tried this but with this approach textbox is not accessible because it is in the createuserwizard control..
Harpreet_125 31-May-14 3:33am    
when i create new application and drag and drop createuserwizard then it is working fine.. what should be the possible reason?
Add RequiredFieldValidator
ASP.NET
<asp:TextBox runat="server" id="txtName" />
  <asp:RequiredFieldValidator runat="server" id="reqName" controltovalidate="txtName" errormessage="Please enter your name!" />


reference:
http://asp.net-tutorials.com/validation/required-field-validator/[^]
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.requiredfieldvalidator(v=vs.110).aspx[^]

UPDATE 1:
add Display="Dynamic" and try by removing Validation Group if you have any. if you added validation group then you need to have the same validation group for the post back control.
ASP.NET
<asp:RequiredFieldValidator ID="reqName" ControlToValidate="txtName" Display="Dynamic" ErrorMessage="Please enter your name!" runat="server"></asp:RequiredFieldValidator>

UPDATE 2:
I have to go back to your previous answer and find your code. The issue is you haven't give the ValidationGroup for the text boxes. if you using ValidationGroup you need to set it for the all the controls and validators you need to validate. do the changes and test your application, I have added sample code for one text box in below.
ASP.NET
<asp:TextBox ID="UserName" runat="server" ValidationGroup="CreateUserWizard2"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate= "UserName" ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="CreateUserWizard2" Display="Dynamic" >*</asp:RequiredFieldValidator>
 
Share this answer
 
v5
Comments
Nirav Prabtani 31-May-14 3:06am    
my 5+
DamithSL 31-May-14 3:06am    
Thank you Nirav
Harpreet_125 31-May-14 3:09am    
I am doing same like this but it is still being postback.. i don't know why...
DamithSL 31-May-14 3:25am    
how we know exactly what you doing!
You think that we have access to your code?
go and update the question with your related code first
DamithSL 31-May-14 4:00am    
check my update

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900