How to expand Jquery Slider Panel programatically? - c#

I have JQuery Silder panel for Login | Register option. for referencing i have include demo of this slider Jquery Login | Register Slider Panel
the actually problem was how to expand programatically this slider when located Literal control have value in Login Section or Register New account section. for understanding this problem i putting my design code.
<asp:Panel ID="Panel_Login_Register" runat="server" CssClass="Panel_Slide">
<div id="toppanel">
<div id="panel">
<div class="content clearfix">
<asp:Panel ID="Panel_Welcome" runat="server" CssClass="left">
<h1>Welcome to Om Investment</h1>
<p class="grey">Om Investment Stock Market Research Trading & Advisory, the most successful market
trading team and has predicted the market direction always ahead of others, our
powerful and high volume Market Gains trading team will deliver high returns to
the Capital invested by clients, We have a consistent success ratio genuine more than
80% in every type of Market.</p>
</asp:Panel>
<asp:Panel ID="Panel_Login" runat="server" CssClass="left" Width="200px" DefaultButton="btnlogin">
<h1>Member Login</h1>
<asp:Label ID="Label2" runat="server" Text="Username:" CssClass="grey" AssociatedControlID="txtusername"></asp:Label>
<cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender4" runat="server" TargetControlID="txtusername" WatermarkText="Enter username here"/>
<asp:TextBox ID="txtusername" runat="server" CssClass="field" ValidationGroup="Login"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="<span style='color:Black'><b>Required Field Missing</b><br />Username is required.</span>"
ControlToValidate="txtusername" ValidationGroup="Login" Display="None" SetFocusOnError="true"></asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender2" runat="server" TargetControlID="RequiredFieldValidator2"
Width="200px" HighlightCssClass="highlight" WarningIconImageUrl="images/1329542890_dialog-warning.png"
CloseImageUrl="images/close.gif">
</cc1:ValidatorCalloutExtender>
<asp:Label ID="Label3" runat="server" Text="Password:" CssClass="grey" AssociatedControlID="txtpassword"></asp:Label>
<cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender12" runat="server" TargetControlID="txtpassword"
WatermarkText="123456789"/>
<asp:TextBox ID="txtpassword" runat="server" CssClass="field" ValidationGroup="Login" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="<span style='color:Black'><b>Required Field Missing</b><br />Password is required.</span>"
ControlToValidate="txtpassword" ValidationGroup="Login" Display="None"></asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender3" runat="server" TargetControlID="RequiredFieldValidator3"
Width="200px" HighlightCssClass="highlight" WarningIconImageUrl="images/1329542890_dialog-warning.png"
CloseImageUrl="images/close.gif">
</cc1:ValidatorCalloutExtender><br />
<asp:CheckBox ID="chk_remember" runat="server"/> <asp:Label ID="Label4" runat="server" Text="Remeber Me ?" CssClass="grey"></asp:Label>
<div class="clear"></div>
<asp:Button ID="btnlogin" runat="server" Text="Login" CssClass="bt_login" ValidationGroup="Login" OnClick="btnlogin_Click" />
<a class="lost-pwd" href="password_recover.aspx"> Lost your password ?</a>
<div class="clear"></div>
<p class="grey"><asp:Literal ID="ltr_error" runat="server"></asp:Literal></p>
</asp:Panel>
<asp:Panel ID="Panel_Register" runat="server" CssClass="left right" DefaultButton="btn_register" Width="356px">
<h1>Create New Account</h1>
<p class="grey">(All the fields are compulsory)</p>
<table><tr><td><asp:Label id="Label6" runat="server" Text="Your Name*" AssociatedControlID="txtname" CssClass="grey"></asp:Label> <cc1:TextBoxWatermarkExtender id="TextBoxWatermarkExtender5" watermarkText="Enter your name" runat="server" TargetControlID="txtname">
</cc1:TextBoxWatermarkExtender> <cc1:FilteredTextBoxExtender id="FilteredTextBoxExtender2" runat="server" TargetControlID="txtname" ValidChars=" ,." FilterType="UppercaseLetters,LowercaseLetters,Custom">
</cc1:FilteredTextBoxExtender></td></tr>
<tr><td><asp:TextBox id="txtname" runat="server" CssClass="field" ValidationGroup="SignUp" MaxLength="50"></asp:TextBox> <asp:RequiredFieldValidator id="RequiredFieldValidator5" runat="server" ValidationGroup="SignUp" SetFocusOnError="true" Display="None" ControlToValidate="txtname" ErrorMessage="<span style='color:Black'><b>Required Field Missing</b><br />Your name is required.</span>"></asp:RequiredFieldValidator> <cc1:ValidatorCalloutExtender id="ValidatorCalloutExtender4" runat="server" TargetControlID="RequiredFieldValidator5" Width="200px" CloseImageUrl="images/close.gif" WarningIconImageUrl="images/1329542890_dialog-warning.png" HighlightCssClass="highlight">
</cc1:ValidatorCalloutExtender></td></tr>
<tr><td><asp:Label id="Label7" runat="server" Text="Your Username*" AssociatedControlID="txtusername1" CssClass="grey"></asp:Label> <cc1:TextBoxWatermarkExtender id="TextBoxWatermarkExtender6" watermarkText="Enter your username" runat="server" TargetControlID="txtusername1">
</cc1:TextBoxWatermarkExtender> <cc1:FilteredTextBoxExtender id="FilteredTextBoxExtender3" runat="server" TargetControlID="txtusername" FilterType="UppercaseLetters,LowercaseLetters,Numbers,Custom">
</cc1:FilteredTextBoxExtender></td></tr>
<tr><td><asp:TextBox id="txtusername1" runat="server" CssClass="field" ValidationGroup="SignUp" MaxLength="50"></asp:TextBox><asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="txtusername1" OnServerValidate="CustomValidator1_ServerValidate" SetFocusOnError="True" ValidationGroup="SignUp" CssClass="grey" ErrorMessage="<span style='color:Gray'>Username is already exist</span>"></asp:CustomValidator></td></tr>
<tr><td><asp:RequiredFieldValidator id="RequiredFieldValidator6" runat="server" ValidationGroup="SignUp" SetFocusOnError="true" Display="None" ControlToValidate="txtusername1" ErrorMessage="<span style='color:Black'><b>Required Field Missing</b><br />Your username is required.</span>"></asp:RequiredFieldValidator> <cc1:ValidatorCalloutExtender id="ValidatorCalloutExtender7" runat="server" TargetControlID="RequiredFieldValidator6" Width="200px" CloseImageUrl="images/close.gif" WarningIconImageUrl="images/1329542890_dialog-warning.png" HighlightCssClass="highlight">
</cc1:ValidatorCalloutExtender></td></tr>
<tr><td><asp:Label id="Label9" runat="server" Text="Your Account Password*" AssociatedControlID="txtpass" CssClass="grey"></asp:Label> <cc1:FilteredTextBoxExtender id="FilteredTextBoxExtender4" runat="server" TargetControlID="txtpass" ValidChars="." FilterType="UppercaseLetters,LowercaseLetters,Numbers,Custom" InvalidChars=" ,'">
</cc1:FilteredTextBoxExtender> <cc1:TextBoxWatermarkExtender id="TextBoxWatermarkExtender7" watermarkText="1234567890" runat="server" TargetControlID="txtpass">
</cc1:TextBoxWatermarkExtender></td></tr>
<tr><td><asp:TextBox id="txtpass" runat="server" CssClass="field" ValidationGroup="SignUp" MaxLength="15" TextMode="Password"></asp:TextBox> <cc1:PasswordStrength id="PasswordStrength1" runat="server" TargetControlID="txtpass" RequiresUpperAndLowerCaseCharacters="false" MinimumSymbolCharacters="0" MinimumNumericCharacters="0" StrengthStyles="TextIndicator_TextBox1_Strength1;TextIndicator_TextBox1_Strength2;TextIndicator_TextBox1_Strength3;TextIndicator_TextBox1_Strength4;TextIndicator_TextBox1_Strength5" TextStrengthDescriptions="Very Poor;Weak;Average;Strong;Excellent" HelpStatusLabelID="TextBox1_HelpLabel" PrefixText="Strength:" PreferredPasswordLength="10" StrengthIndicatorType="Text" DisplayPosition="RightSide"></cc1:PasswordStrength> <asp:RequiredFieldValidator id="RequiredFieldValidator7" runat="server" ValidationGroup="SignUp" SetFocusOnError="true" Display="None" ControlToValidate="txtpass" ErrorMessage="<span style='color:Black'><b>Required Field Missing</b><br />Your account password is required.</span>"></asp:RequiredFieldValidator> <cc1:ValidatorCalloutExtender id="ValidatorCalloutExtender8" runat="server" TargetControlID="RequiredFieldValidator7" Width="200px" CloseImageUrl="images/close.gif" WarningIconImageUrl="images/1329542890_dialog-warning.png" HighlightCssClass="highlight">
</cc1:ValidatorCalloutExtender></td></tr>
<tr><td><asp:Label id="Label10" runat="server" Text="Confirm Password*" AssociatedControlID="txtcpass" CssClass="grey"></asp:Label><cc1:TextBoxWatermarkExtender id="TextBoxWatermarkExtender8" watermarkText="1234567890" runat="server" TargetControlID="txtcpass">
</cc1:TextBoxWatermarkExtender> <cc1:FilteredTextBoxExtender id="FilteredTextBoxExtender5" runat="server" TargetControlID="txtpass" ValidChars="." FilterType="UppercaseLetters,LowercaseLetters,Numbers,Custom" InvalidChars=" ,'">
</cc1:FilteredTextBoxExtender></td></tr>
<tr><td><asp:TextBox id="txtcpass" runat="server" CssClass="field" ValidationGroup="SignUp" MaxLength="15" TextMode="Password"></asp:TextBox> <asp:RequiredFieldValidator id="RequiredFieldValidator8" runat="server" ValidationGroup="SignUp" SetFocusOnError="true" Display="None" ControlToValidate="txtcpass" ErrorMessage="<span style='color:Black'><b>Required Field Missing</b><br />Confirm password is required.</span>"></asp:RequiredFieldValidator> <asp:CompareValidator id="CompareValidator1" runat="server" ValidationGroup="SignUp" SetFocusOnError="true" Display="None" ControlToValidate="txtcpass" ErrorMessage="<span style='color:Black'><b>Entered Field is Invalid</b><br />Your new password and confirm password doesn't mathched.</span>" ControlToCompare="txtpass"></asp:CompareValidator> <cc1:ValidatorCalloutExtender id="ValidatorCalloutExtender9" runat="server" TargetControlID="RequiredFieldValidator8" Width="200px" CloseImageUrl="images/close.gif" WarningIconImageUrl="images/1329542890_dialog-warning.png" HighlightCssClass="highlight">
</cc1:ValidatorCalloutExtender> <cc1:ValidatorCalloutExtender id="ValidatorCalloutExtender11" runat="server" TargetControlID="CompareValidator1" Width="200px" CloseImageUrl="images/close.gif" WarningIconImageUrl="images/1329542890_dialog-warning.png" HighlightCssClass="highlight">
</cc1:ValidatorCalloutExtender></td></tr>
<tr><td><asp:Label id="Label12" runat="server" Text="Your Birth Date*" AssociatedControlID="txtbdate" CssClass="grey"></asp:Label> <cc1:TextBoxWatermarkExtender id="TextBoxWatermarkExtender10" watermarkText="Enter your birthdate" runat="server" TargetControlID="txtbdate">
</cc1:TextBoxWatermarkExtender></td></tr>
<tr><td><asp:TextBox id="txtbdate" runat="server" CssClass="field" ValidationGroup="SignUp"></asp:TextBox> <asp:RequiredFieldValidator id="RequiredFieldValidator10" runat="server" ValidationGroup="SignUp" SetFocusOnError="true" Display="None" ControlToValidate="txtbdate" ErrorMessage="<span style='color:Black'><b>Required Field Missing</b><br />Your birthdate is required.</span>"></asp:RequiredFieldValidator> <asp:RegularExpressionValidator id="RegularExpressionValidator3" runat="server" ValidationGroup="SignUp" SetFocusOnError="true" Display="None" ControlToValidate="txtbdate" ErrorMessage="<span style='color:Black'><b>Entered Field is Invalid</b><br/>Birth date format should be like: DD/MM/yyyy</span>" ValidationExpression="^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$"></asp:RegularExpressionValidator> <cc1:CalendarExtender id="CalendarExtender1" runat="server" TargetControlID="txtbdate" PopupButtonID="img_cal" Format="dd/MM/yyyy">
</cc1:CalendarExtender> <cc1:MaskedEditExtender id="MaskedEditExtender5" runat="server" TargetControlID="txtbdate" ErrorTooltipEnabled="True" AcceptNegative="Left" DisplayMoney="Left" MaskType="Date" OnInvalidCssClass="MaskedEditError" OnFocusCssClass="MaskedEditFocus" MessageValidatorTip="true" Mask="99/99/9999"></cc1:MaskedEditExtender> <cc1:ValidatorCalloutExtender id="ValidatorCalloutExtender13" runat="server" TargetControlID="RequiredFieldValidator10" Width="200px" CloseImageUrl="images/close.gif" WarningIconImageUrl="images/1329542890_dialog-warning.png" HighlightCssClass="highlight">
</cc1:ValidatorCalloutExtender> <cc1:ValidatorCalloutExtender id="ValidatorCalloutExtender14" runat="server" TargetControlID="RegularExpressionValidator3" Width="200px" CloseImageUrl="images/close.gif" WarningIconImageUrl="images/1329542890_dialog-warning.png" HighlightCssClass="highlight">
</cc1:ValidatorCalloutExtender></td></tr>
<tr><td><asp:Label id="Label11" runat="server" Text="Your e-mail*" AssociatedControlID="txtemail" CssClass="grey"></asp:Label><cc1:TextBoxWatermarkExtender id="TextBoxWatermarkExtender9" watermarkText="Enter your email" runat="server" TargetControlID="txtemail">
</cc1:TextBoxWatermarkExtender></td></tr>
<tr>
<td><asp:TextBox id="txtemail" runat="server" CssClass="field" ValidationGroup="SignUp" MaxLength="50"></asp:TextBox><asp:CustomValidator ID="CustomValidator2" runat="server" ValidationGroup="SignUp" ControlToValidate="txtemail" SetFocusOnError="true" OnServerValidate="CustomValidator2_ServerValidate" CssClass="grey" ErrorMessage="<span style='color:Gray'>Email is already exist</span>"></asp:CustomValidator></td></tr>
<tr><td><asp:RequiredFieldValidator id="RequiredFieldValidator9" runat="server" ValidationGroup="SignUp" SetFocusOnError="true" Display="None" ControlToValidate="txtemail" ErrorMessage="<span style='color:Black'><b>Required Field Missing</b><br />Your email is required.</span>"></asp:RequiredFieldValidator> <asp:RegularExpressionValidator id="RegularExpressionValidator2" runat="server" ValidationGroup="SignUp" SetFocusOnError="true" Display="None" ControlToValidate="txtemail" ErrorMessage="<span style='color:Black'><b>Entered Field is Invalid</b><br/>Email format should be like: name#domain.com</span>" ValidationExpression="^[\w-\.]{1,}\#([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,6}$"></asp:RegularExpressionValidator> <cc1:ValidatorCalloutExtender id="ValidatorCalloutExtender10" runat="server" TargetControlID="RequiredFieldValidator9" Width="200px" CloseImageUrl="images/close.gif" WarningIconImageUrl="images/1329542890_dialog-warning.png" HighlightCssClass="highlight">
</cc1:ValidatorCalloutExtender> <cc1:ValidatorCalloutExtender id="ValidatorCalloutExtender12" runat="server" TargetControlID="RegularExpressionValidator2" Width="200px" CloseImageUrl="images/close.gif" WarningIconImageUrl="images/1329542890_dialog-warning.png" HighlightCssClass="highlight">
</cc1:ValidatorCalloutExtender></td></tr>
<tr><td><asp:Label id="Label13" runat="server" Text="Your Phone no*" AssociatedControlID="txtphoneno" CssClass="grey"></asp:Label> <cc1:TextBoxWatermarkExtender id="TextBoxWatermarkExtender11" watermarkText="Enter your phone no" runat="server" TargetControlID="txtphoneno">
</cc1:TextBoxWatermarkExtender> <cc1:FilteredTextBoxExtender id="FilteredTextBoxExtender6" runat="server" TargetControlID="txtphoneno" FilterType="Numbers">
</cc1:FilteredTextBoxExtender></td></tr>
<tr>
<td><asp:TextBox id="txtphoneno" runat="server" CssClass="field" ValidationGroup="SignUp" MaxLength="10"></asp:TextBox><asp:CustomValidator ID="CustomValidator3" runat="server" ValidationGroup="SignUp" ControlToValidate="txtphoneno" SetFocusOnError="true" OnServerValidate="CustomValidator3_ServerValidate" CssClass="grey" ErrorMessage="<span style='color:Gray'>Phone no is already exist</span>"></asp:CustomValidator></td>
</tr>
<tr><td><asp:RequiredFieldValidator id="RequiredFieldValidator11" runat="server" ValidationGroup="SignUp" SetFocusOnError="true" Display="None" ControlToValidate="txtphoneno" ErrorMessage="<span style='color:Black'><b>Required Field Missing</b><br />Your phone no is required.</span>"></asp:RequiredFieldValidator><asp:RegularExpressionValidator id="RegularExpressionValidator4" runat="server" ValidationGroup="SignUp" SetFocusOnError="true" Display="None" ControlToValidate="txtphoneno" ErrorMessage="<span style='color:Black'><b>Entered Field is Invalid</b><br/>Phone no format should like : 9000000098<br/> +91 Not Needed<span>" ValidationExpression="^((\\+91-?)|0)?[0-9]{10}$"></asp:RegularExpressionValidator> <cc1:ValidatorCalloutExtender id="ValidatorCalloutExtender15" runat="server" TargetControlID="RequiredFieldValidator11" Width="200px" CloseImageUrl="images/close.gif" WarningIconImageUrl="images/1329542890_dialog-warning.png" HighlightCssClass="highlight">
</cc1:ValidatorCalloutExtender> <cc1:ValidatorCalloutExtender id="ValidatorCalloutExtender16" runat="server" TargetControlID="RegularExpressionValidator4" Width="200px" CloseImageUrl="images/close.gif" WarningIconImageUrl="images/1329542890_dialog-warning.png" HighlightCssClass="highlight">
</cc1:ValidatorCalloutExtender></td></tr>
<tr><td><asp:Button ID="btn_register" runat="server" Text="Register" ValidationGroup="SignUp" CssClass="bt_register" OnClick="btn_register_Click"/></td></tr>
</table>
<div class="clear"></div>
<p class="grey"><asp:Literal ID="ltr_message2" runat="server"></asp:Literal></p>
</asp:Panel>
</div>
</div>
<div class="tab">
<ul class="login">
<li class="left"> </li>
<li>Hello Guest!</li><li class="sep">|</li><li id="toggle">
<a id="open" class="open" href="#">Log In | Register</a>
<a id="close" style="display: none;" class="close" href="#">Close Panel</a>
</li>
<li class="right"> </li>
</ul>
</div>
</div>
</asp:Panel>
this slider works fine but i have no idea to how to auto expand this panel if one of the Literal have value.
In Register New Account panel i have also custome validators also i have to found the way to expand this panel if one the three custome validator throws Error message.
For details referencing i have also include js/slide.js file content:
$(document).ready(function() {
// Expand Panel
$("#open").click(function(){
$("div#panel").slideDown("slow");
});
// Collapse Panel
$("#close").click(function(){
$("div#panel").slideUp("slow");
});
// Switch buttons from "Log In | Register" to "Close Panel" on click
$("#toggle a").click(function () {
$("#toggle a").toggle();
});
});
_____________________Updated Code_____________________
this code is about how i append my custome error to literal control
protected void btnlogin_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
using (SqlConnection conn = Util.GetConnection())
{
conn.Open();
SqlCommand cmd = new SqlCommand("sp_CheckUserAccount", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("#UserName", SqlDbType.VarChar).Value = txtusername.Text.Trim();
cmd.Parameters.Add("#pass", SqlDbType.VarChar).Value = txtpassword.Text.Trim();
cmd.Parameters.Add("#Error", SqlDbType.NVarChar, 100).Direction = ParameterDirection.Output;
SqlParameter sqlParam = cmd.Parameters.Add("#Return Value", SqlDbType.Int);
sqlParam.Direction = System.Data.ParameterDirection.ReturnValue;
cmd.ExecuteNonQuery();
int returnValue = (int)cmd.Parameters["#Return Value"].Value;
if (returnValue == 1)
{
if (chk_remember.Checked == true)
{
conn.Close();
cmd.Dispose();
conn.Open();
SqlCommand cmd1 = new SqlCommand("sp_Read_User_Type", conn);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.Add(new SqlParameter("#Userid", SqlDbType.VarChar, 50, "Id"));
cmd1.Parameters["#Userid"].Value = txtusername.Text.Trim();
SqlDataReader reader = cmd1.ExecuteReader();
while (reader.Read())
{
if (reader["Type_name"].ToString() == "Admin")
{
Response.Cookies["UName"].Value = txtusername.Text;
Response.Cookies["PWD"].Value = txtpassword.Text;
Response.Cookies["UName"].Expires = DateTime.Now.AddMonths(2);
Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(2);
Session["username"] = reader["Id"].ToString();
Response.Redirect("~/Admin/Admin_Landing_page.aspx");
}
else
{
Response.Cookies["UName"].Value = txtusername.Text;
Response.Cookies["PWD"].Value = txtpassword.Text;
Response.Cookies["UName"].Expires = DateTime.Now.AddMonths(2);
Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(2);
Session["username"] = reader["Id"].ToString();
Response.Redirect("~/EndUser/myhome.aspx");
}
}
reader.Close();
}
else
{
Response.Cookies["UName"].Expires = DateTime.Now.AddMonths(-1);
Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(-1);
conn.Close();
cmd.Dispose();
conn.Open();
SqlCommand cmd1 = new SqlCommand("sp_Read_User_Type", conn);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.Add(new SqlParameter("#Userid", SqlDbType.VarChar, 50, "Id"));
cmd1.Parameters["#Userid"].Value = txtusername.Text.Trim();
SqlDataReader reader = cmd1.ExecuteReader();
while (reader.Read())
{
if (reader["Type_name"].ToString() == "Admin")
{
Session["username"] = reader["Id"].ToString();
Response.Redirect("~/Admin/Admin_Landing_page.aspx");
}
else
{
Session["username"] = reader["Id"].ToString();
Response.Redirect("~/EndUser/myhome.aspx");
}
}
reader.Close();
}
}
else
{
ltr_error.Text = (string)cmd.Parameters["#Error"].Value; }
}
}
}

http://www.roorkichap.com/sliding-login-panel-built-with-jquery-asp-net-vb-net-and-sql-server-2000/
download the source code and check out

Updated version:
Literal doesn't generate any tag on page. Therefore you need to set id for tag that wrap your Literal. (or something more suitable for you)
<p id="p_error" class="grey"><asp:Literal ID="ltr_error" runat="server"></asp:Literal></p>
After that you can use js for check any text.
$(document).ready(function() {
if ($("#p_error").text() != "") //choose condition more suitable for you
$("div#panel").slideDown("slow");
});

Related

Prevent Browser (Chrome) from autofilling the username login textbox

I would like to prevent chrome browser from auto filling the username Textbox in the account login.aspx page that I have created.
I have tried setting the Textbox's AutoCompleteMode property to "None" or to "Disabled" but still nothing.
My front end code for login:
<asp:Login ID="LoginUser" runat="server" EnableViewState="false" RenderOuterTable="false" onloggedin="LoginUser_LoggedIn">
<LayoutTemplate>
<span class="failureNotification">
<asp:Literal ID="FailureText" runat="server"></asp:Literal>
</span>
<asp:ValidationSummary ID="LoginUserValidationSummary" runat="server" CssClass="failureNotification"
ValidationGroup="LoginUserValidationGroup"/>
<div class="accountInfo">
<fieldset class="login">
<legend><asp:Literal ID="Literal3" runat="server" Text="<%$ Resources:chienvh.language, AccountInformation%>" /></legend>
<p>
<%--<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</asp:Label>--%>
<asp:TextBox ID="UserName" runat="server" CssClass="textEntry" AutoPostBack="true" Placeholder="<%$ Resources:chienvh.language, Username%>" OnTextChanged="UserName_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" CssClass="failureNotification"
ErrorMessage="User Name is required." ToolTip="User Name is required."
ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p>
<%--<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>--%>
<asp:TextBox ID="Password" runat="server" CssClass="passwordEntry" TextMode="Password" Placeholder="<%$ Resources:chienvh.language, Password%>"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
CssClass="failureNotification" ErrorMessage="Password is required." ToolTip="Password is required."
ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p>
<asp:DropDownList runat="server" ID="DDLSite" DataSourceID="DSSite" DataValueField="SiteID" DataTextField="Site"></asp:DropDownList>
<asp:SqlDataSource runat="server" ID="DSSite" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
SelectCommand="Select 'Επίλέξτε Site...' [Site], 0 SiteID
union
Select [Site], [SiteID]
from Site
order by [Site]"></asp:SqlDataSource>
</p>
<p>
<asp:CheckBox ID="RememberMe" runat="server"/>
<asp:Label ID="RememberMeLabel" runat="server" AssociatedControlID="RememberMe" CssClass="inline">Keep me logged in</asp:Label>
</p>
</fieldset>
<p class="submitButton">
<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="LoginUserValidationGroup"/>
</p>
</div>
</LayoutTemplate>
</asp:Login>
And the back end:
protected void LoginUser_LoggedIn(object sender, EventArgs e)
{
string error = "";
string User_Name = LoginUser.UserName.ToString();
if (Common.Is_Inactive_User(User_Name, ref error) || error != "")
FormsAuthentication.SignOut();
Roles.DeleteCookie();
Session.Clear();
}

Conflict between two buttons. The signout button enters in requiredfieldvalidator, but I don't want that

I have two buttons, one to ADD=Button1 and one to signout=BtnSingout.
When I push signout it doesn't redirect to my default page. Instead, it enters in required field validation error message.To signout I need to complete all the textboxes.
Also i have an if where if I push button Adauga(ADD) and I have a textbox not filled it needs to show me an error in msjadd, but it's doing nothing. To add info to database I need to complete all the textboxes.
Here is the code in apsx.cs:
protected void Button1_Click(object sender, EventArgs e)
{
int Salar_negociat = 0;
int Salar_realizat = 0;
int Vechime = 0;
int Spor = 0;
int Premii_brute = 0;
int Compensatie = 0;
int Avans = 0;
int Retineri = 0;
if (nume.Text == "" || prenume.Text == "" || functie.Text == "" || salar_negociat.Text == ""
|| salar_realizat.Text == "" || vechime.Text == "" || spor.Text == "" || premii_brute.Text == ""
|| compensatie.Text == "" || avans.Text == "" || retineri.Text == "")
{
msjadd.ForeColor = System.Drawing.Color.Red;
msjadd.Text = " Exista casute necompletate , va rugam sa le completati";
}
else
{
Salar_negociat = Convert.ToInt16(salar_negociat.Text);
Salar_realizat = Convert.ToInt16(salar_realizat.Text);
Vechime = Convert.ToInt16(vechime.Text);
Spor = Convert.ToInt16(spor.Text);
Premii_brute = Convert.ToInt16(premii_brute.Text);
Compensatie = Convert.ToInt16(compensatie.Text);
Avans = Convert.ToInt16(avans.Text);
Retineri = Convert.ToInt16(retineri.Text);
try
{
con.Open();
strSQL = "insert into angajati (nume,prenume,functie,salar_negociat,salar_realizat,vechime,spor,premii_brute,compensatie,avans,retineri) values ('" + nume.Text + "','" + prenume.Text + "','" + functie.Text + "'," + Salar_negociat + "," + Salar_realizat + "," + Vechime + "," + Spor + "," + Premii_brute + "," + Compensatie + "," + Avans + "," + Retineri + ")";
cm = new OleDbCommand(strSQL, con);
i = cm.ExecuteNonQuery();
nume.Text = "";
prenume.Text = "";
functie.Text = "";
salar_negociat.Text = "";
salar_realizat.Text = "";
vechime.Text = "";
spor.Text = "";
premii_brute.Text = "";
compensatie.Text = "";
avans.Text = "";
retineri.Text = "";
msjadd.Text = "Adăugare cu succes";
}
catch (OleDbException ex)
{
}
finally
{
if (con.State == ConnectionState.Open)
con.Close();
}
}
}
protected void btnSingout_Click(object sender, EventArgs e)
{
Session["Username"] = null;
Response.Redirect("Default.aspx");
}
}
The code in aspx is this :
<div class="center-page1">
<div class="col-xs-12">
<asp:Label ID="numeangajati" runat="server" Text="Nume"></asp:Label>
<asp:TextBox ID="nume" CssClass="form-control" Placeholder="Nume" name="name" runat="server" Title="Introduceți caractere de forma Aa..." data-toggle="tooltip" data-placement="right" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Câmp gol" ForeColor="Red" Display="Dynamic" ControlToValidate="nume"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ForeColor="Red" ErrorMessage="Nume invalid" Display="Dynamic" ControlToValidate="nume" ValidationExpression="^[A-Z][Za-z]+((\s)?((\'|\-|\.)?([A-Z][Za-z])+))*$"></asp:RegularExpressionValidator>
</div>
<div class="col-xs-12">
<asp:Label ID="Label1" runat="server" Text="Prenume"></asp:Label>
<asp:TextBox ID="prenume" placeholder="Prenume" CssClass="form-control" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Câmp gol" ForeColor="Red" ControlToValidate="prenume" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ForeColor="Red" ErrorMessage="Prenume invalid" Display="Dynamic" ControlToValidate="prenume" ValidationExpression="^[A-Z][Za-z]+((\s)?((\'|\-|\.)?([A-Z][Za-z])+))*$"></asp:RegularExpressionValidator>
</div>
<div class="col-xs-12">
<asp:Label ID="Label2" runat="server" Text="Functie"></asp:Label>
<asp:TextBox ID="functie" placeholder="Functie" CssClass="form-control" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Câmp gol" ForeColor="Red" ControlToValidate="functie" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ForeColor="Red" ErrorMessage="Funcție invalidă" Display="Dynamic" ControlToValidate="functie" ValidationExpression="^[A-Z][Za-z\s]+$"></asp:RegularExpressionValidator>
</div>
<div class="col-xs-12">
<asp:Label ID="Label3" runat="server" Text="Salar negociat"></asp:Label>
<asp:TextBox ID="salar_negociat" CssClass="form-control" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ForeColor="Red" ErrorMessage="Câmp invalid" ControlToValidate="salar_negociat" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ErrorMessage="Salar negociat invalid" Display="Dynamic" ControlToValidate="salar_negociat" ValidationExpression="^[0-9]*$"></asp:RegularExpressionValidator>
</div>
<div class="col-xs-12">
<asp:Label ID="Label4" runat="server" Text="Salar realizat(%)"></asp:Label>
<asp:TextBox ID="salar_realizat" CssClass="form-control" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ForeColor="Red" ErrorMessage="Câmp gol" ControlToValidate="salar_realizat" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator3" runat="server" ForeColor="Red" ErrorMessage="Salar realizat invalid" Display="Dynamic" MinimumValue="0" MaximumValue="100" ControlToValidate="salar_realizat" Type="Integer"></asp:RangeValidator>
</div>
<div class="col-xs-12">
<asp:Label ID="Label5" runat="server" Text="Vechime(%)"></asp:Label>
<asp:TextBox ID="vechime" CssClass="form-control" text="0" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ForeColor="Red" ErrorMessage="Câmp gol" ControlToValidate="vechime" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server" ForeColor="Red" ErrorMessage="Vechime invalidă" Type="Integer" MinimumValue="0" MaximumValue="100" ControlToValidate="vechime" Display="Dynamic"></asp:RangeValidator>
</div>
<div class="col-xs-12">
<asp:Label ID="Label10" runat="server" Text="Spor(%)"></asp:Label>
<asp:TextBox ID="spor" CssClass="form-control" text="0" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ForeColor="Red" ErrorMessage="Câmp gol" Display="Dynamic" ControlToValidate="spor"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator2" runat="server" ForeColor="Red" ErrorMessage="Spor invalid" Type="Integer" MinimumValue="0" MaximumValue="100" Display="Dynamic" ControlToValidate="spor"></asp:RangeValidator>
</div>
<div class="col-xs-12">
<asp:Label ID="Label6" runat="server" Text="Premii brute"></asp:Label>
<asp:TextBox ID="premii_brute" CssClass="form-control" runat="server">0</asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator7" runat="server" ForeColor="Red" ErrorMessage="Premii brute invalide" Display="Dynamic" ControlToValidate="premii_brute" ValidationExpression="^[0-9]*$"></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ForeColor="Red" ErrorMessage="Câmp gol" ControlToValidate="premii_brute" Display="Dynamic"></asp:RequiredFieldValidator>
</div>
<div class="col-xs-12">
<asp:Label ID="Label7" runat="server" Text="Compensatii"></asp:Label>
<asp:TextBox ID="compensatie" CssClass="form-control" runat="server">0</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ForeColor="Red" ErrorMessage="Câmp gol" ControlToValidate="compensatie" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator8" runat="server" ForeColor="Red" ErrorMessage="Compensații invalide" Display="Dynamic" ControlToValidate="compensatie" ValidationExpression="^[0-9]*$"></asp:RegularExpressionValidator>
</div>
<div class="col-xs-12">
<asp:Label ID="Label8" runat="server" Text="Avans"></asp:Label>
<asp:TextBox ID="avans" CssClass="form-control" runat="server" Text="0"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ForeColor="Red" ErrorMessage="Câmp gol" ControlToValidate="avans" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator6" runat="server" ForeColor="Red" ErrorMessage="Avans invalid" Display="Dynamic" ControlToValidate="avans" ValidationExpression="^[0-9]*$"></asp:RegularExpressionValidator>
</div>
<div class="col-xs-12">
<asp:Label ID="Label9" runat="server" Text="Retineri"></asp:Label>
<asp:TextBox ID="retineri" CssClass="form-control" runat="server" Text="0"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ForeColor="Red" ErrorMessage="Câmp gol" ControlToValidate="retineri" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server" ForeColor="Red" ErrorMessage="Rețineri invalide" Display="Dynamic" ControlToValidate="retineri" ValidationExpression="^[0-9]*$"></asp:RegularExpressionValidator>
</div>
<div class="col-xs-12 space-vert space-bottom-footer">
<asp:Button ID="Button1" class="btn btn-success" runat="server" Text="Adaugare" OnClick="Button1_Click" />
<asp:Label ID="msjadd" runat="server" Text="" ForeColor="#33CC33" ></asp:Label>
</div>
</div>
Add validation group for all the RequiredFieldValidators and the add button. example
<asp:Button ID="Button1" ValidationGroup="AddValidationGroup" ....
and
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" ValidationGroup="AddValidationGroup" ...
do the same for all the asp:RequiredFieldValidators

Procedure SP_BGTable has no parameters and arguments were supplied

This is my stored procedure :
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[Insert_BranchRegistration]
#branchname varchar(100),
#address nvarchar(200),
#phone bigint,
#email varchar(200),
#bloodgroup int,
#nobags int
as
INSERT INTO [dbo].[BranchRegistration]
([branchname]
,[address]
,[phone]
,[email]
,[bloodgroup]
,[nobags])
VALUES
(#branchname
,#address
,#phone
,#email
,#bloodgroup
,#nobags)
GO
ALTER procedure [dbo].[SP_BGTable] as SELECT [bgid] ,[name] FROM [dbo].[BGTable]
This is my asp.net html code.
<%# Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="BranchRegi.aspx.cs" Inherits="BloodBank.BranchRegi" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div class="pagecontent">
<div class="addform">
<asp:Button ID="BtnAdd" runat="server" CssClass="button" Text="Add" />
<br />
<asp:Label ID="ErrorMessage" ForeColor="Red" class="label_inv" runat="server" ></asp:Label>
<br />
</div>
<div class="form">
<div class="border-line">
<div>
<span class="width"> <asp:Label ID="lblBranchName" class="label_inv" runat="server" Text="Branch Name"></asp:Label></span>
<span class="leftmargin">
<asp:TextBox ID="txtBranchName" class="textbox_body" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RfvBranchName" runat="server" ForeColor="Red" ErrorMessage="Please enter branch name." ControlToValidate="txtBranchName"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rxvBranchName" runat="server"
ControlToValidate="txtBranchName" ErrorMessage="Only alphabets are allowed"
ForeColor="Red" ValidationExpression="[a-zA-Z]+"> </asp:RegularExpressionValidator></span>
</div>
<br />
<div>
<span class="width"> <asp:Label ID="lblAddress" class="label_inv" runat="server" Text="Address"></asp:Label></span>
<span style="margin-left:95px"> <asp:TextBox ID="txtAddress" Style="height: 70px" class="textbox_body" runat="server" TextMode="multiLine"></asp:TextBox>
<asp:RequiredFieldValidator ID="RfvAddress" ForeColor="Red" runat="server" ErrorMessage="Please enter Address." ControlToValidate="txtAddress"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rxvAddress" runat="server"
ControlToValidate="txtAddress" ErrorMessage="Only alphabets are allowed"
ForeColor="Red" ValidationExpression="[a-zA-Z]+" > </asp:RegularExpressionValidator></span>
</div>
<br />
<div>
<span class="width"> <asp:Label ID="lblPhoneNumber" class="label_inv" runat="server" Text="Phone Number"></asp:Label></span>
<span class="leftmargin" style="margin-left:50px"> <asp:TextBox ID="txtPhonenumber" class="textbox_body" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RfvPhonenumber" ForeColor="Red" runat="server" ErrorMessage="Please enter phone number." ControlToValidate="txtPhonenumber"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtPhonenumber" ErrorMessage="Please enter valid mobile number"
ValidationExpression="[0-9]{10}"></asp:RegularExpressionValidator></span>
</div>
<br />
<div>
<span class="width"> <asp:Label ID="lblEmailID" class="label_inv" runat="server" Text="Email ID"></asp:Label></span>
<span class="leftmargin" style="margin-left:85px" ><asp:TextBox ID="txtEmailID" class="textbox_body" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEmailID" ForeColor="Red" runat="server" ErrorMessage="Please enter email." ControlToValidate="txtEmailID"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2"
runat="server" ErrorMessage="Please Enter Valid Email ID"
ValidationGroup="vgSubmit" ControlToValidate="txtEmailID"
CssClass="requiredFieldValidateStyle"
ForeColor="Red"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*">
</asp:RegularExpressionValidator></span>
</div>
<br />
<div>
<span class="width"><asp:Label ID="lblGroup" class="label_inv" runat="server" Text="Blood Group"></asp:Label></span>
<span class="leftmargin">
<asp:DropDownList ID="ddlBlood" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvBloodGroup" ForeColor="Red" runat="server" ErrorMessage="Please enter valid group name." ControlToValidate="ddlBlood"></asp:RequiredFieldValidator>
</span>
</div>
<br />
<div>
<span class="width"> <asp:Label ID="lblNoBags" class="label_inv" runat="server" Text="No. of Bags"></asp:Label></span>
<span class="leftmargin"><asp:TextBox ID="txtNoBags" Style="margin-left: 5px" class="textbox_body" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvNoBags" ForeColor="Red" runat="server" ErrorMessage="Please enter branch name." ControlToValidate="txtNoBags"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator id="RegularExpressionValidator4"
ControlToValidate="txtNoBags"
ValidationExpression="\d+"
Display="Static"
EnableClientScript="true"
ErrorMessage="Please enter numbers only"
runat="server"/></span>
</div>
<br />
<div>
<span class="width" style="margin-left:200px" ><asp:Button ID="invSubmit" runat="server" Text="Submit" OnClick="invSubmit_Click" /></span>
<span style="margin-left:50px" > <asp:Button ID="invReset" runat="server" Text="Reset" /></span>
</div>
</div>
</div>
</div>
<link href="Content/site1.css" rel="stylesheet" />
<style>
.leftmargin
{
margin-left:60px;
}
.width
{
width:200px;
}
</style>
</asp:Content>
and server side C# code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using BloodBank.Controllers;
using BloodBank.Models;
namespace BloodBank
{
public partial class BranchRegi : System.Web.UI.Page
{
#region VARIABLES
DataSet ds = null;
BranchRegistration objBranch;
Operation objOperation;
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
filldrop();
ddlBlood.SelectedIndex = 0;
}
}
public void filldrop()
{
ds = SqlHelper.ExecuteDataset(Common.GetConnectionString(), CommandType.StoredProcedure, CommanName.StoredProcedures.Select_Group);
ddlBlood.DataSource = ds;
ddlBlood.DataTextField = "name";
ddlBlood.DataValueField = "bgid";
ddlBlood.DataBind();
ddlBlood.Items.Insert(0, new ListItem("Select", "0"));
}
protected void invSubmit_Click(object sender, EventArgs e)
{
objBranch = new BranchRegistration();
objOperation = new Operation();
try
{
objBranch.branchname = txtBranchName.Text.Trim();
objBranch.address = txtAddress.Text.Trim();
objBranch.phone = Int64.Parse(txtPhonenumber.Text.Trim());
objBranch.email = txtEmailID.Text.Trim();
//Response.Write(ddlBlood.SelectedValue.ToString());
objBranch.bloodgroup = int.Parse(ddlBlood.SelectedItem.Value);
objBranch.nobags = int.Parse(txtNoBags.Text.Trim());
objOperation.RegisterBranch(objBranch);
ErrorMessage.Text = CommanName.Messages.registerSuccess;
}
catch (Exception)
{
ErrorMessage.Text = CommanName.Messages.registerUnsuccess;
}
}
}
}
and
int iResult = SqlHelper.ExecuteNonQuery(Common.GetConnectionString(), CommandType.StoredProcedure,CommanName.StoredProcedures.Select_Group, new SqlParameter("#branchname", objBranch.branchname), new SqlParameter("#address", objBranch.address), new SqlParameter("#phone", objBranch.phone), new SqlParameter("#email", objBranch.email), new SqlParameter("#bloodgroup", objBranch.bloodgroup), new SqlParameter("#nobags", objBranch.nobags));
The exception is:
Procedure SP_BGTable has no parameters and arguments were supplied.
ALTER procedure [dbo].[SP_BGTable] as SELECT [bgid] ,[name] FROM [dbo].[BGTable]
This is store procedure SP_BGTable. and there is no parameters! But you try to pass parameter in code.
I think you calling the wrong procedure. Change it to Insert_BranchRegistration

asp.net objects empty in form

Been using PHP for a long time but now am making a site with ASP.NET. I am attempting to have a basic user registration form but whenever I submit the form, all the data shows to be empty! Also, the tagsinput method doesnt seem to be working.
Here is a basic form, it is in a contentplaceholder. The entire body in the master page is surrounded in a <form runat="server">
<script type="text/javascript">
$(document).ready(function () {
//$("[id$=pick_user_type]").hide();
$("[id$=UserTypeList]").click(function (e) { //second step of registration
$('[id$=UserTypeList] input:checked').each(function () {
//artist
if ((this.value).toLowerCase().indexOf("artist") >= 0) {
$('#whatinstruments').show();
$('#instrumentsplayedtags').prop('disabled', false);
}
//producer
if ((this.value).toLowerCase().indexOf("producer") >= 0) {
$('#whatrecordingplatforms').show();
$('#recordingplatformstags').prop('disabled', false);
}
});
$('[id$=UserTypeList] input:not(:checked)').each(function () { //unchecked
//artist
if ((this.value).toLowerCase().indexOf("artist") >= 0) {
$('#whatinstruments').hide();
$('#instrumentsplayedtags').prop('disabled', true);
}
//producer
if ((this.value).toLowerCase().indexOf("producer") >= 0) {
$('#whatrecordingplatforms').hide();
$('#recordingplatformstags').prop('disabled', true);
}
});
});
$('#artistslikedtags').tagsInput({ //tags for listener
width: 'auto'
});
$('#instrumentsplayedtags').tagsInput({ //tags for artist
width: 'auto'
});
$('#recordingplatformstags').tagsInput({ //tags for producer
width: 'auto'
});
});
function onNextClick() {
//alert(Page_ClientValidate("UserInformation"));
//if (Page_ClientValidate("UserInformation")) {
$("[id$=registration_div]").hide('slide', { direction: 'left' }, 1000);
$("[id$=pick_user_type]").css('position', 'absolute');
$("[id$=pick_user_type]").show('slide', { direction: 'right' }, 1000);
//}
}
function onLeftClick() {
//alert(Page_ClientValidate("UserInformation"));
//if (Page_ClientValidate("UserInformation")) {
$("[id$=pick_user_type]").hide('slide', { direction: 'right' }, 1000);
$("[id$=registration_div]").show('slide', { direction: 'left' }, 1000);
//}
}
</script>
<div id="registration_div">
<table id="registration_table">
<td>
<div id="registration">
<table id="user_information_table">
<tr>
<%--first name and last name--%>
<td>
<asp:TextBox ID="FirstName" runat="server" CssClass="roundedcorner"></asp:TextBox>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkFirstName" runat="server" TargetControlID="FirstName" WatermarkText="First Name" WatermarkCssClass="watermarked roundedcorner" />
<asp:RequiredFieldValidator ID="FirstNameRequired" runat="server" ControlToValidate="FirstName" ErrorMessage="First Name is required." ToolTip="First Name is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkLastName" runat="server" TargetControlID="LastName" WatermarkText="Last Name" WatermarkCssClass="watermarked roundedcorner" />
<asp:TextBox ID="LastName" runat="server" CssClass="roundedcorner"></asp:TextBox>
<asp:RequiredFieldValidator ID="LastNameRequired" runat="server" ControlToValidate="LastName" ErrorMessage="Last Name is required." ToolTip="Last Name is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<%--username--%>
<td>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkUsername" runat="server" TargetControlID="Username" WatermarkText="Username" WatermarkCssClass="watermarked roundedcorner" />
<asp:TextBox ID="UserName" runat="server" CssClass="roundedcorner"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<%--password and confirm pass--%>
<td>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkPassword" runat="server" TargetControlID="Password" WatermarkText="Password" WatermarkCssClass="watermarked roundedcorner" />
<asp:TextBox ID="Password" runat="server" TextMode="Password" CssClass="roundedcorner"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="UserInformation"><font color="red" >*</font></asp:RequiredFieldValidator>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkConfirmPassword" runat="server" TargetControlID="ConfirmPassword" WatermarkText="Confirm Password" WatermarkCssClass="watermarked roundedcorner" />
<asp:TextBox ID="ConfirmPassword" runat="server" CssClass="roundedcorner" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword" ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
</td>
</tr>
<%--email and confirm email--%>
<tr>
<td>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkEmail" runat="server" TargetControlID="Email" WatermarkText="Email" WatermarkCssClass="watermarked roundedcorner" />
<asp:TextBox ID="Email" runat="server" Columns="48" CssClass="roundedcorner"></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="Email" ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ValidationExpression="\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*" ForeColor="Red" ControlToValidate="Email" ValidationGroup="UserInformation" ErrorMessage="Invalid Email Format"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkConfirmEmail" runat="server" TargetControlID="ConfirmEmail" WatermarkText="Confirm Email" WatermarkCssClass="watermarked roundedcorner" />
<asp:TextBox ID="ConfirmEmail" runat="server" Columns="48" CssClass="roundedcorner"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ConfirmEmail" ErrorMessage="Confirm E-mail is required." ToolTip="Confirm E-mail is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regexEmailValid" runat="server" ValidationExpression="\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*" ForeColor="red" ControlToValidate="ConfirmEmail" ValidationGroup="UserInformation" ErrorMessage="Invalid Email Format"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<%-- location --%>
<td>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkLocation" runat="server" TargetControlID="Location" WatermarkText="Location" WatermarkCssClass="watermarked roundedcorner" />
<asp:TextBox ID="Location" runat="server" Columns="48" CssClass="roundedcorner"></asp:TextBox>
<asp:RequiredFieldValidator ID="LocationValidator" runat="server" ControlToValidate="Location" ErrorMessage="Location is required." ToolTip="Location is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<%-- birthdate --%>
<td>
<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkBirthdate" runat="server" TargetControlID="Birthdate" WatermarkText="Birthdate (mm/dd/yyyy)" WatermarkCssClass="watermarked roundedcorner" />
<asp:TextBox ID="Birthdate" runat="server" CssClass="roundedcorner"></asp:TextBox>
<asp:RequiredFieldValidator ID="BirthdayRequired" runat="server" ControlToValidate="Birthdate" ErrorMessage="Birthdate is required." ToolTip="Security question is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
<asp:CompareValidator ErrorMessage="(mm/dd/yyyy)" Display="Dynamic" ID="valcDate" ControlToValidate="Birthdate" Operator="DataTypeCheck" Type="Date" ForeColor="red" runat="server" ValidationGroup="UserInformation"></asp:CompareValidator>
<asp:RangeValidator ID="valrDate" runat="server" ControlToValidate="Birthdate" MinimumValue="12/31/1950" MaximumValue="1/1/2100" Type="Date" Text="Invalid Date" ForeColor="Red" Display="Dynamic" ValidationGroup="UserInformation" />
</td>
</tr>
<tr>
<%-- gender --%>
<td>
<%--<ajaxToolkit:TextBoxWatermarkExtender ID="WatermarkGender" runat="server" TargetControlID="Gender" WatermarkText="Birthdate (mm/dd/yyyy)" WatermarkCssClass="watermarked" />--%>
<asp:DropDownList ID="Gender" runat="server" CssClass="roundedcorner">
<asp:ListItem Value="Gender"></asp:ListItem>
<asp:ListItem Value="Male"></asp:ListItem>
<asp:ListItem Value="Female"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator InitialValue="Gender" ID="GenderRequired" runat="server" ControlToValidate="Gender" ErrorMessage="Gender is required." ToolTip="Gender is required." ValidationGroup="UserInformation"><font color="red">*</font></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td style="color: Red;">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td>
<asp:CompareValidator ID="comparePasswords" runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword" ErrorMessage="Your passwords do not match!" ForeColor="red" Display="Dynamic" ValidationGroup="UserInformation" />
<asp:CompareValidator ID="EmailComparitor" runat="server" ControlToCompare="Email" ControlToValidate="ConfirmEmail" ErrorMessage="Your emails do not match!" ForeColor="Red" Display="Dynamic" ValidationGroup="UserInformation" />
<br />
<%--<asp:RegularExpressionValidator ID="PasswordRegExValidator" runat="server" ValidationExpression="^.*(?=.{8,35})(?=.*\d)(?=.*[a-zA-Z]).*$" ForeColor="Red" ControlToValidate="Password" ValidationGroup="UserInformation" ErrorMessage="Your Password must be at least 8 charaters long and contain at least 1 number."></asp:RegularExpressionValidator>--%>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<asp:ImageButton ID="NextButton" ClientIDMode="Static" runat="server" ImageUrl="images/registration/arrowright.png"
Height="50px" onmouseover="this.src='images/registration/arrowrightgreen.png'" onmouseout="this.src='images/registration/arrowright.png'" ValidationGroup="UserInformation" OnClientClick="onNextClick()" AutoPostBack="False" OnClick="NextButton_Click"/>
</div>
<%--STEP 2--%>
<div id="pick_user_type">
<asp:ImageButton ID="LeftButton" runat="server" ImageUrl="images/registration/arrowleft.png"
Height="50px" onmouseover="this.src='images/registration/arrowleftgreen.png'"
onmouseout="this.src='images/registration/arrowleft.png'" ValidationGroup="UserSelectGroup"
OnClientClick="onLeftClick()" AutoPostBack="False"/>
<h2>Almost Done! Tell us a little more information.</h2>
<br />
<div id="pick_user_list">
<strong>Check Those That Apply to Your User Experience</strong>
<asp:CheckBoxList ID="UserTypeList" runat="server">
<asp:ListItem Selected="True" Value="Listener" Enabled="False"> Listener</asp:ListItem>
<asp:ListItem Value="Artist"> Artist</asp:ListItem>
<asp:ListItem Value="Producer"> Producer</asp:ListItem>
<asp:ListItem Value="Promoter"> Promoter</asp:ListItem>
</asp:CheckBoxList>
<br />
<strong>What music artists do you like?</strong>
<input id="artistslikedtags" type="text" class="tags" value="" runat="server" />
<br />
<div id="whatinstruments" style="display: none">
<strong>What instruments do you play?</strong>
<input id="instrumentsplayedtags" type="text" class="tags" value="" disabled="disabled" runat="server"/>
</div>
<br />
<div id="whatrecordingplatforms" style="display: none">
<strong>What recording platforms or equipment do you use?</strong>
<input id="recordingplatformstags" type="text" class="tags" value="" disabled="disabled" runat="server"/>
</div>
<br />
<strong>What mobile platform do you use?</strong><br />
<asp:DropDownList ID="MobilePlatforms" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="iOS">iOS (Apple)</asp:ListItem>
<asp:ListItem Value="Android">Android</asp:ListItem>
<asp:ListItem Value="Windows">Windows</asp:ListItem>
<asp:ListItem Value="Blackberry">Blackberry</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator InitialValue="" ID="MobilePlatformsValidator" runat="server" ControlToValidate="MobilePlatforms" ErrorMessage="This field is required." ToolTip="This field is required." ValidationGroup="UserTypeInformation" ClientIDMode="Static"><font color="red">*</font></asp:RequiredFieldValidator>
<div style="text-align: right">
<asp:Button ID="Finish" runat="server" Text="Finish" ControlToValidate="MobilePlatforms" OnClick="FinishButton_Click" UseSubmitBehavior="False" ValidationGroup="MobilePlatforms" />
</div>
</div>
</div>
Then behind the scenes just a simple method call.
protected void FinishButton_Click(object sender, EventArgs e)
{
MembershipAdapter ma = new MembershipAdapter();
Boolean b = ma.CreateUser(UserName.Text, Email.Text, Password.Text, FirstName.Text, LastName.Text, Gender.Text, Location.Text, Birthdate.Text, MobilePlatforms.Text, "0", "0", "0", artistslikedtags.Value);
}
When I place a breakpoint on the createUser() method, all the text in the objects passed through the method are EMPTY strings!! Does anyone have an idea why this could be?
I have tried ASP.NET AutoPostBack is clearing form data
Are you doing anything during Page_Load that is setting the textbox values to blank? If that's the case you need to wrap these with
if(!Page.IsPostback)
{
//put your initialisation code for them here
}
because otherwise when you submit the form, they will be cleared every time.
Also, unkess I am going blind in my old age, there is no <form> tag in the above code?
You need to learn the various stages of the ASP.NET page lifecycle, as without understanding the basics of this, it will seem very strange of what is actually going on with ASP.NET.
Watch ASP.NET training for beginners : ASP.NET Page Life Cycle and pay specific attention to the Page_Load event, as this is where you will tend to do a lot of your work, especially dynamic content creation.
In your posted example, understanding that you can do certain things the first time the page loads versus on subsequent page requests (called postbacks), then you do the following in your page's Page_Load event:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Do things here that you only want to happen when the page first loads
}
else
{
// Do things here every time the page is requested, except for the first time
}
}

Gridview UpdatePanel when update gridview disappear

I got a gridview to show user data and a item hyperlink when click will populate the data on below table for admin to update.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<fieldset>
<div style="float: left;">
<h2>
Members</h2>
</div>
<div style="float: right; padding-right: 30px;">
Create Member
</div>
<div style="clear: both;" />
<hr />
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None" DataKeyNames="UserID" BorderWidth="1px"
CellPadding="4" ForeColor="Black" GridLines="Horizontal" Width="886px" EnableSortingAndPagingCallbacks="true">
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:BoundField DataField="email" HeaderText="Email" />
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# "~/member.aspx?UserID="+ DataBinder.Eval(Container.DataItem,"UserID") %>'
Text='View'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
</ContentTemplate>
<Triggers>
<div class="formlabel">
Index :</div>
<div class="formlabel">
<asp:Label ID="userID" runat="server" Text=""></asp:Label></div>
<br />
<div class="formlabel">
Login Name :</div>
<asp:TextBox ID="username" runat="server" MaxLength="40"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="username" ID="RequiredFieldValidator1"
runat="server" ErrorMessage="Username can't be null" Display="None">
</asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" runat="server" TargetControlID="RequiredFieldValidator1" />
<asp:CustomValidator ID="CustomValidator6" runat="server" ControlToValidate="username"
Display="None" ErrorMessage="Username already exists." ClientValidationFunction="CheckUniqueness"
OnServerValidate="UserNameExistsValidator_ServerValidate"></asp:CustomValidator>
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender14" runat="server" PopupPosition="Right"
TargetControlID="CustomValidator6">
</cc1:ValidatorCalloutExtender>
<br />
<div class="formlabel">
Password :</div>
<asp:TextBox ID="password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="password" ID="RequiredFieldValidator2"
runat="server" ErrorMessage="Password can't be null" Display="None">
</asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender2" runat="server" TargetControlID="RequiredFieldValidator2">
</cc1:ValidatorCalloutExtender>
<br />
<div class="formlabel">
First Name :</div>
<asp:TextBox ID="firstname" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="firstname" ID="RequiredFieldValidator3"
runat="server" ErrorMessage="First Name can't be null" Display="None">
</asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender3" runat="server" TargetControlID="RequiredFieldValidator3">
</cc1:ValidatorCalloutExtender>
<br />
<div class="formlabel">
Last Name :</div>
<asp:TextBox ID="lastname" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="lastname" ID="RequiredFieldValidator4"
runat="server" ErrorMessage="Last Name can't be null" Display="None">
</asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender4" runat="server" TargetControlID="RequiredFieldValidator4">
</cc1:ValidatorCalloutExtender>
<br />
<div class="formlabel">
Email :</div>
<asp:TextBox ID="email" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="lastname" ID="RequiredFieldValidator5"
runat="server" ErrorMessage="Email can't be null" Display="None">
</asp:RequiredFieldValidator>
<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender5" runat="server" TargetControlID="RequiredFieldValidator5">
</cc1:ValidatorCalloutExtender>
<asp:RegularExpressionValidator ID="REVEmail" runat="server" ControlToValidate="email"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="Invalid Email"
Display="None"></asp:RegularExpressionValidator>
<cc1:ValidatorCalloutExtender ID="REVEmail_ValidatorCalloutExtender" runat="server"
TargetControlID="REVEmail">
</cc1:ValidatorCalloutExtender>
<br />
<br />
<asp:Label ID="msg" runat="server" Text=""></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Update" />
<br />
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
Below are my backend code:
if (Page.IsValid)
{
string id = Request.QueryString["UserID"];
string firstnamevalue = firstname.Text;
string lastnamevalue = lastname.Text;
string emailvalue = email.Text;
MySqlConnection connect = new MySqlConnection(connectionString);
MySqlCommand command = connect.CreateCommand();
command.CommandText = "Update user set Email = '" + emailvalue + "', FirstName ='" + firstnamevalue + "' , LastName ='" + lastnamevalue + "' WHERE UserID =" + id;
try
{
connect.Open();
command.Connection = connect;
command.ExecuteNonQuery();
GridView1.DataBind();
UpdatePanel2.Update();
}
catch
{
msg.Text = "Error Occured";
}
finally
{
connect.Close();
}
}
When I tried update the gridview will gone, may I know what is with my code?

Categories