Urgent .....................!
Reply
![]() |
|
From:
![]() SwapnilDeshmukh
|
Hi,
I have a solution to your problem but little bit of _javascript_ you have to use not for validating the control but to enable or disable the validation control as per requirement.
Do the Following steps to achieve the solution
1)Initial requirement a.Three Server side Textbox (txtSearch, txtUserName, txtPassword) b.Three Server side Required field validator each for the Textbox and set the Enabled Property to False. c.Two buttons one for submiting the user name and Password and other for search textbox. 2) Assign the control to validate attribute of each required field validator for the required textbox. 3) Create two _javascript_ function a.EnableUserName_Password() b.EnableSearch() 4) In the EnableUserName_Password() function enable the Required field validator for User Name and Password 5) In the EnableSearch () function enable the Required field validator Search 6) Attached the EnableUserName_Password() to the Submit button through code behind (for e.g.; btnSubmit.Attributes.Add("onclick","EnableUserName_Password();");) 7) Attached the EnableSearch () to the Search button through code behind (for e.g.; btnSearch.Attributes.Add("onclick"," EnableSearch();");)
The Code is pasted here
The HTML Starts here
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="Validation.WebForm1" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>WebForm1</title> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"> <meta content="C#" name="CODE_LANGUAGE"> <meta content="_javascript_" name="vs_defaultClientScript"> <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> <script language="_javascript_"> function EnableUserName_Password() { document.getElementById("RequiredFieldValidator2").setAttribute("enabled","True"); document.getElementById("RequiredFieldValidator3").setAttribute("enabled","True"); }
function EnableSearch() { document.getElementById("RequiredFieldValidator1").setAttribute("enabled","True"); } </script> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <TABLE id="Table1" style="Z-INDEX: 101; LEFT: 160px; POSITION: absolute; TOP: 96px" cellSpacing="1" cellPadding="1" width="300" border="1"> <TR> <TD></TD> <TD> <asp:TextBox id="txtsearch" runat="server"></asp:TextBox> <asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="Search Not Empty" ControlToValidate="txtsearch" Enabled="False"></asp:RequiredFieldValidator></TD> </TR> <TR> <TD></TD> <TD> <asp:TextBox id="txtusername" runat="server"></asp:TextBox> <asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server" ErrorMessage="User Name Not Empty" ControlToValidate="txtusername" Enabled="False"></asp:RequiredFieldValidator></TD> </TR> <TR> <TD></TD> <TD> <asp:TextBox id="txtpassword" runat="server"></asp:TextBox> <asp:RequiredFieldValidator id="RequiredFieldValidator3" runat="server" ErrorMessage="Password Not Empty" ControlToValidate="txtpassword" Enabled="False"></asp:RequiredFieldValidator></TD> </TR> <TR> <TD></TD> <TD> <asp:Button id="btnSubmit" runat="server" Text="Submit"></asp:Button> <asp:Button id="btnSearch" runat="server" Text="Search"></asp:Button></TD> </TR> </TABLE> </form> </body> </HTML>
The HTML Ends here
The Code behind Starts here
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls;
namespace Validation { /// <summary> /// Summary description for WebForm1. /// </summary> public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox txtsearch; protected System.Web.UI.WebControls.TextBox txtusername; protected System.Web.UI.WebControls.TextBox txtpassword; protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1; protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2; protected System.Web.UI.WebControls.Button btnSubmit; protected System.Web.UI.WebControls.Button btnSearch; protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
private void Page_Load(object sender, System.EventArgs e) { btnSubmit.Attributes.Add("onclick","EnableUserName_Password();"); btnSearch.Attributes.Add("onclick","EnableSearch();"); }
#region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load);
} #endregion } }
The code behind ends here
Hope this help u
Reply if u have any problem
Swapnil Deshmukh
|
|
View other groups in this category.
![]() |
To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings.
Need help? If you've forgotten your password, please go to Passport Member Services.
For other questions or feedback, go to our Contact Us page.
If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list.
Remove my e-mail address from dotNET User Group Hyd.
|
|