JavaScript Function - c#

I want to store TextBox value in HidenField and i am calling javascript function on button click function is calling getting message Hi but... textBox getting null....I am using asp.net TextBox and also i have tried with HTML textBox also but same scenario happing in both the case...Actually HTML code using in Ajax Tab Container may be this problem ...
How to solve such type of problem
function f11() {
alert("Hi")
alert("hi..." + document.getElementById("txthtmltextbox").value)
document.getElementById("txtuncheaderHF").value = document.getElementById("txthtmltextbox").value;
document.getElementById("txtrootFolderHF").value = document.getElementById("txthtmltextboxroot").value
}
This is my HTML code
<asp:Panel ID="pnlhfconfig" runat="server" Height="100%" Width="100%">
<table bordercolor="gainsboro" bgcolor="white" style="border-bottom-width: 1px; border-bottom-style: solid;
border-top-width: 1px; border-top-style: solid; border-left-width: 1px; border-left-style: solid;
border-right-width: 1px; border-right-style: solid; border-bottom-color: #8C8B83;
border-top-color: #8C8B83; border-left-color: #8C8B83; border-right-color: #8C8B83;"
id="TABLE2" language="javascript">
<tbody>
<tr>
<td colspan="3" bgcolor="#E5E5E5" height="20" class="topnav" style="font-size: 10px;
font-family: verdana">
<font style="color: #000000"><strong>
<asp:Literal ID="Literal4" runat='server' Text='HF Configuration'></asp:Literal>  </strong></font>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbluncheader" runat="server" Text='HotFolder UNCHeader'></asp:Label>
</td>
<td>
<input type="text" id="txthtmltextbox" name="txthtmltextbox" onblur="f1()" runat="server" MaxLength="50" Style="z-index: 102;" Width="250px" />
<asp:RequiredFieldValidator ID="rfvuncheader" runat="server"
ErrorMessage="UNCHeader is required." ControlToValidate="txthtmltextbox" Display="None"
ValidationGroup="save"></asp:RequiredFieldValidator>
</td>
<td>
<asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="Red" Text="*"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblrootfolder" runat="server" Text='Hot RootFolder'></asp:Label>
</td>
<td>
<input type="text" id="txthtmltextboxroot" name="txthtmltextboxroot" runat="server" MaxLength="50" Style="z-index: 102;" Width="250px" />
<%-- <asp:TextBox ID="txtrootfolder" runat="server" MaxLength="50" Width="250px"></asp:TextBox>--%><asp:RequiredFieldValidator
ID="rfvUNH" runat="server" ErrorMessage="RootFolder is required." ControlToValidate="txthtmltextboxroot"
Display="None" ValidationGroup="save"></asp:RequiredFieldValidator>
</td>
<td>
<asp:Label ID="Label2" runat="server" Font-Bold="True" ForeColor="Red" Text="*"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<table>
<tr>
<td>
<asp:Button ID="btnsave" OnClientClick ="f1()" runat="server" Text='Save' Width="55px" BackColor="#E5E5E5"
ForeColor="Black" ValidationGroup="save" />
</td>
<td>
<asp:Button ID="btncancel" runat="server" Text='Cancel' Width="55px" BackColor="#E5E5E5"
ForeColor="Black" />
</td>
</tr>
<tr>
<td>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
ShowSummary="False" ValidationGroup="save" />
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</asp:Panel>

Hope you aware of JQuery and using JQuery, you will easily get inner control of panel. Because when your page is render on browser. Html code is something different then .NET(ASPX page).
You will get/set panel inner control value using below statement.
$("#<%=pnlhfconfig.ClientID %> input[id='<%= txtuncheaderHF.ClientID %>']").val($("#<%=pnlhfconfig.ClientID %> input[id='<%= txthtmltextbox.ClientID %>']").val());

You are using txthtmltextbox please check on console what is the actual ID of control while generating html.
Or use as
document.getElementById("<%= txthtmltextbox.ClientID%>").value

Related

Why does my clear button only clear the text boxes if the validations are true?

i am making a signup form and it has a clear button. the form has validations for all the text boxes to make sure they are true.
I have a clear button and it works but only if the validations are true which is not what i want, i would like it to clear no matter what, is there a way to do that?
here is my code for the event handler for the clear button
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
TextBoxEmail.Text = String.Empty;
TextBoxEmail2.Text = String.Empty;
TextBoxPassword1.Text = String.Empty;
TextBoxPassword2.Text = String.Empty;
TextBoxUsername.Text = String.Empty;
TextBoxWebsite.Text = String.Empty;
}
here is the other code for the webpage
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="Project5.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Sign Up Page</title>
<link href="StyleSheet1.css" rel="stylesheet" type="text/css" />
<link href="StyleSheet1.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style3 {
width: 402px;
text-align: left;
}
.auto-style4 {
margin-left: 0px;
}
.auto-style6 {
font-family: "comic Sans MS";
color: #3366FF;
}
.validator {
font-size: small;
color: red;
}
.auto-style7 {
width: 327px;
text-align: center;
}
.auto-style8 {
text-align: right;
}
.auto-style9 {
width: 402px;
text-align: center;
}
</style>
<h1>
<img src="Images/scccLogo.png" />
</h1>
<h2>
Please register you SCCC account
</h2>
</head>
<body>
<form id="form1" runat="server">
<div class="auto-style8">
<div>
</div>
<table class="auto-style1">
<tr>
<td class="auto-style7">
<asp:Label ID="LabelUsrName" runat="server" Text="Please
Enter Your Username:" CssClass="auto-style6"></asp:Label>
</td>
<td class="auto-style3">
<asp:TextBox ID="TextBoxUsername" runat="server"
Width="185px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ControlToValidate="TextBoxUsername" CssClass="validator"
ErrorMessage="* Please Enter A Username"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style7">
<asp:Label ID="LabelPassword" runat="server"
Text="Please Enter Your Password:" CssClass="auto-style6"></asp:Label>
</td>
<td class="auto-style3">
<asp:TextBox ID="TextBoxPassword1" runat="server"
Width="185px" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server" ControlToValidate="TextBoxPassword1" CssClass="validator"
ErrorMessage="* Please Enter A Password"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style7">
<asp:Label ID="LabelPasswordRepeat" runat="server"
Text="Please Enter Your Password Again:" CssClass="auto-style6"></asp:Label>
</td>
<td class="auto-style3">
<asp:TextBox ID="TextBoxPassword2" runat="server"
Width="185px" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3"
runat="server" ControlToValidate="TextBoxPassword2" CssClass="validator"
ErrorMessage="* Please Enter A Password"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1"
runat="server" ControlToCompare="TextBoxPassword1"
ControlToValidate="TextBoxPassword2" CssClass="validator" ErrorMessage="*
Passwords Do Not Match"></asp:CompareValidator>
</td>
</tr>
<tr>
<td class="auto-style7">
<asp:Label ID="LabelEmail" runat="server" Text="Please
Enter A Valid Email Address:" CssClass="auto-style6"></asp:Label>
</td>
<td class="auto-style3">
<asp:TextBox ID="TextBoxEmail" runat="server"
Width="185px" TextMode="Email"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4"
runat="server" ControlToValidate="TextBoxEmail" CssClass="validator"
ErrorMessage="* Please Enter An Email"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator2" runat="server"
ControlToValidate="TextBoxEmail" CssClass="validator" ErrorMessage="* Please
Enter A Valid Email" ValidationExpression="\w+([-+.']\w+)*#\w+
([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style7">
<asp:Label ID="LabelEmail2" runat="server" Text="Please
Enter Your Email Again:" CssClass="auto-style6"></asp:Label>
</td>
<td class="auto-style3">
<asp:TextBox ID="TextBoxEmail2" runat="server"
Width="185px" TextMode="Email"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5"
runat="server" ControlToValidate="TextBoxEmail2" CssClass="validator"
ErrorMessage="* Please Enter An Email"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator2"
runat="server" ControlToCompare="TextBoxEmail"
ControlToValidate="TextBoxEmail2" CssClass="validator" ErrorMessage="*
Emails Do Not Match"></asp:CompareValidator>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator3" runat="server"
ControlToValidate="TextBoxEmail2" CssClass="validator" ErrorMessage="*
Please Enter A Valid Email" ValidationExpression="\w+([-+.']\w+)*#\w+
([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style7">
<asp:Label ID="LabelWebsite" runat="server" Text="Please
Enter Your Website" CssClass="auto-style6"></asp:Label>
</td>
<td class="auto-style3">
<asp:TextBox ID="TextBoxWebsite" runat="server"
CssClass="auto-style4" Width="185px" TextMode="Url"></asp:TextBox>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBoxWebsite" CssClass="validator" ErrorMessage="*
Please Enter A Valid URL" ValidationExpression="http(s)?://([\w-]+\.)+[\w-]+
(/[\w- ./?%&=]*)?"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style7">
<asp:Label ID="Label1" runat="server"
CssClass="validator" Text="* Required Field"></asp:Label>
</td>
<td class="auto-style9">
<asp:ImageButton ID="ImageButtonClear" runat="server"
CssClass="auto-style4" Height="105px" ImageUrl="~/Images/32293367-red-clear-
button.jpg" OnClick="ImageButton2_Click" Width="112px" />
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="~/Images/go.jpg" OnClick="ImageButton1_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Your ImageButton causes validation, which is the default. I think you just have to add CausesValidation="false" attribute like this :
<asp:ImageButton ID="ImageButtonClear" runat="server"
CssClass="auto-style4" Height="105px" ImageUrl="~/Images/32293367-red-clear-
button.jpg" OnClick="ImageButton2_Click" CausesValidation="false" Width="112px" />
Cf. https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.imagebutton.causesvalidation?view=netframework-4.7.2

How to control button from panel

I am new to ASP.NET. I have taken a Panel. Inside the Panel, I have taken a table. Inside the table there are TextBox, RadioButton and a Button controls.
I have written some code in button_click event.
But nothing happens. button_click event is not firing.
What to do now ?
I have also some other things in panel. But no click event is working.
Code is below:
<asp:Panel ID="Pnlproducts" runat="server" ScrollBars="Auto" Height="500px" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px">
<asp:DataList ID="DLProducts" runat="server" RepeatColumns="3" Width="600px" OnSelectedIndexChanged="DLProducts_SelectedIndexChanged">
<ItemTemplate >
<table align="left" class="auto-style6" style="border-color:#9900FF;border-left:1px;border-right:1px;border-top:1px;">
<tr>
<td style="border-color: #000000; border-width: 1px; border-bottom-style: ridge" class="auto-style8">
<asp:Label ID="lblProductName" runat="server" Text="<%# Bind('ProductName') %>" Font-Bold="True"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style9">
<asp:Image ID="Image2" runat="server" Height="160px" ImageUrl="<%# Bind('ProductImage') %>" Width="173px" Style="border:ridge 1px black" />
</td>
</tr>
<tr>
<td class="auto-style9"><strong>Price:</strong><asp:Label ID="lblPrice" runat="server" Text="<%# Bind('ProductPrice') %>" Font-Bold="True" ForeColor="Red"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style9">
<asp:Button ID="Addtocartbtn" runat="server" BorderStyle="Solid" BorderWidth="1px" OnClick="Addtocartbtn_Click" Text="Add to Cart" Width="170px" BorderColor="Black" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</asp:Panel>
<asp:Panel ID="Panel111" runat="server" ScrollBars="Auto" Height="500px" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px">
<table class="auto-style16">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</asp:Panel>
</td>
<td>
<asp:Panel ID="pnlCatagory" runat="server" Height="500px" ScrollBars="Auto" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px">
<div class="auto-style7">
<asp:DataList ID="dlCatagory" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<ItemTemplate>
<asp:LinkButton ID="LBTNCatagoty" runat="server" CommandArgument="<%# Bind('CatagoryID') %>" Font-Bold="True" OnClick="LBTNCatagoty_Click" Text="<%# Bind('CatagoryName') %>"></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</div>
</asp:Panel>
<asp:Panel ID="Panel222" runat="server" Height="500px" ScrollBars="Auto" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px">
<table class="auto-style10">
<tr>
<td class="auto-style7" colspan="2"><strong>Please Type Your Details</strong></td>
</tr>
<tr>
<td class="auto-style12"></td>
<td class="auto-style11"></td>
</tr>
<tr>
<td class="auto-style15">Name :</td>
<td class="johnykbd8">
<asp:TextBox ID="TextBoxUserName" runat="server" Width="180px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15">E-mail :</td>
<td class="johnykbd8">
<asp:TextBox ID="TextBoxEmail" runat="server" Width="180px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15">Address:</td>
<td class="johnykbd8">
<asp:TextBox ID="TextBoxAdress" runat="server" Height="90px" TextMode="MultiLine" Width="180px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15">Gender :</td>
<td>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="GenderGroup" Text="Male" /><br />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="GenderGroup" Text="Female" />
</td>
</tr>
<tr>
<td class="auto-style15">Mobile:</td>
<td class="johnykbd8">
<asp:TextBox ID="TextBoxMobileNum" runat="server" Width="180px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15">Photo :</td>
<td class="johnykbd8">
<asp:FileUpload ID="FileUploaduserphoto" runat="server" Width="180px" />
</td>
</tr>
<tr>
<td class="auto-style15">Payment :</td>
<td>
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="Paymentgroup" Text="Visa" /><br />
<asp:RadioButton ID="RadioButton4" runat="server" GroupName="Paymentgroup" Text="MasterCard" /><br />
<asp:RadioButton ID="RadioButton5" runat="server" GroupName="Paymentgroup" Text="Cash On Delivery" />
</td>
</tr>
<tr>
<td class="auto-style15">Review :</td>
<td>
<asp:TextBox ID="TextBoxreview" runat="server" Width="180px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15">Total : </td>
<td>BDT :<asp:Label ID="Labelshopamount" runat="server"></asp:Label></td>
</tr>
<tr>
<td colspan="2">
<asp:ImageButton ID="ImageButtonOrderNow" runat="server" ImageUrl="~/Images/Designing/order.jpg" OnClick="ImageButtonOrderNow_Click" Width="250px" />
</td>
</tr>
</table>
</asp:Panel>
If the button is in a datalist or gridview for example, set the CommandName property. The databound object (datalist, gridview) has ItemCommand-event. Put the code in this event.
Pseudo code:
if (e.CommandName.equals(your_command_name)){ label1.text = e.CommandArgument };

Having Issues with using VISIBLE. My Javascript doesnt seem to be handling the event when the check box is clicked

All of my hidden fields have ID's. And in my JavaScript in trying to set the visible from false to true on the payment selection. The Cash payment should just display the address to be sent to. The credit card payment comes up with text boxes and labels in order to process the payment online. But when I run the script the wont appear with the checkbox selection. I assigned an onClick event and still doesnt work. Any suggestions?
<%# Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="ShoppingCart.aspx.cs" Inherits="ShoppingCart" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<head>
<script type="text/javascript">
function paymentFunction() {
if (document.getElementById("rbCash").checked) {
document.getElementById("lbCash").visible = true;
document.getElementById("lbCash2").visible = true;
document.getElementById("lbCash3").visible = true;
document.getElementById("lbCash4").visible = true;
}
else
{
if(document.getElementById("rbCreditCard").checked)
{
document.getElementById("lbCard").visible = true;
document.getElementById("lbCardNum").visible = true;
document.getElementById("lbCVV").visible = true;
document.getElementById("lbexp").visible = true;
document.getElementById("ddlCard").visible = true;
document.getElementById("tbCnum").visible = true;
document.getElementById("tbcvvnum").visible = true;
document.getElementById("tbexp").visible = true;
}
}
}
</script>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 100%;
}
.style3
{
width: 130px;
}
</style>
</head>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<table class="style2">
<tr>
<td class="style3">
Payment Type:</td>
<td>
<asp:CheckBox ID="rbCash" runat="server" onClick="paymentFunction()" Text="Cash" ClientIDMode="Static"/>
<asp:CheckBox ID="rbCreditCard" runat="server" onClick="paymentFunction()" Text="Credit Card" />
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
<asp:Label ID="lbCash" runat="server" ForeColor="Black"
Text="Please Send Payment To:" Visible="False" ClientIDMode="Static"></asp:Label>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
<asp:Label ID="lbCash2" runat="server" ForeColor="Black"
Text="Wild Style Shoes" Visible="False" ClientIDMode="Static"></asp:Label>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
<asp:Label ID="lbCash3" runat="server" ForeColor="Black"
Text="1808 West Avenue" Visible="False" ClientIDMode="Static"></asp:Label>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
<asp:Label ID="lbCash4" runat="server" ForeColor="Black"
Text="Chicago, IL 88947" Visible="False" ClientIDMode="Static"></asp:Label>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="lbcard" runat="server" Text="Card Type" Visible="False"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlCard" runat="server" Visible="False">
<asp:ListItem>Select A Card</asp:ListItem>
<asp:ListItem>Visa</asp:ListItem>
<asp:ListItem>Discover</asp:ListItem>
<asp:ListItem>MasterCard</asp:ListItem>
<asp:ListItem>American Express</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="lbcardnum" runat="server" Text="Card Number:" Visible="False"></asp:Label>
</td>
<td>
<asp:TextBox ID="tbCnum" runat="server" Visible="False" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="lbCVV" runat="server" Text="CVV Number" Visible="False"></asp:Label>
</td>
<td>
<asp:TextBox ID="tbcvvnum" runat="server" Visible="False" Width="58px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
<asp:Label ID="lbexp" runat="server" Text="Expiration Date" Visible="False"></asp:Label>
</td>
<td>
<asp:TextBox ID="tbexp" runat="server" Visible="False"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Submit Payment" Visible="False" />
</td>
</tr>
</table>
<p>
</p>
<p>
</p>
<p>
Thank You For Shopping With Us:<br />
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
</asp:Content>
If you set Visible = false on the server side like you are doing, then the server will not render the control.
You probably want to do the following:
<asp:Label ID="lbCash" runat="server" ForeColor="Black"
Text="Please Send Payment To:" style="visibility:hidden" ClientIDMode="Static"></asp:Label>
Then in the javascript do something like this:
document.getElementById('lbCash').style.visibility = 'visible';

Button in Modal Popup Is not working as it should have to worked

I am Having a code for Modal PopUp windoe in which I wanna perform login operation and code for extender is as follows.
<div class="wrapper">
<ul id="icons">
<li><asp:ImageButton runat="server" ImageUrl="images/lgn.png" ID="btnimg" CssClass="image" /></li>
</ul>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnimg" PopupControlID="Panel1" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender >
<asp:panel id="Panel1" CssClass="popup" runat="server">
<div class="popup">
<div id="PopupHeader" style="height:55px;background-color:#f6f6f6;border-radius:10px;width:348px;font-size:2.7em; "> <font style="margin:30px 0px 0px 20px;vertical-align:middle;color:Black;line-height:1.2em; font-size:37px; font-family: BonvenoCF;"> Login </font></div>
<div class="PopupBody">
<table width="350px" style="vertical-align:middle;text-align:center;">
<tr>
<td style="width:43.5px"> </td>
<td style="width:131.25px"> </td>
<td style="width:131.25px"> </td>
<td style="width:43.5px"> </td>
</tr>
<tr>
<td style="width:43.5px"> </td>
<td style="width:131.25px">
<asp:Label ID="Label1" runat="server" Text="User Name: "></asp:Label>
</td>
<td style="width:131.25px">
<asp:TextBox ID="txtUserName" runat="server" Height="20px" style="border-radius:8px;"> </asp:TextBox>
<asp:TextBoxWatermarkExtender ID="txtUserName_TextBoxWatermarkExtender" runat="server" Enabled="True" TargetControlID="txtUserName"WatermarkText="User Name">
</asp:TextBoxWatermarkExtender>
</td>
<td style="width:43.5px"> </td>
</tr>
<tr>
<td style="width:43.5px"> </td>
<td style="width:131.25px"> </td>
<td style="width:131.25px"> </td>
<td style="width:43.5px"> </td>
</tr>
<tr>
<td style="width:43.5px"> </td>
<td style="width:131.25px">
<asp:Label ID="Label2" runat="server" Text="Password: " ></asp:Label>
</td>
<td style="width:131.25px">
<asp:TextBox ID="txtPassword" runat="server" Height="20px" style="border-radius:8px;"> </asp:TextBox>
<asp:TextBoxWatermarkExtender ID="txtPassword_TextBoxWatermarkExtender"
runat="server" Enabled="True" TargetControlID="txtPassword"
WatermarkText="Password">
</asp:TextBoxWatermarkExtender>
</td>
<td style="width:43.5px"> </td>
</tr>
<tr>
<td style="width:43.5px"> </td>
<td colspan="2">
<asp:Label ID="Label3" runat="server" Text="Invalid User Name Or Password." Visible="False"></asp:Label>
</td>
<td style="width:43.5px"> </td>
</tr>
<tr>
<td style="width: 43.5px"> </td>
<td style="width: 131.25px">
<asp:Button ID="Button2" runat="server" CssClass="button" Text="Login" />
</td>
<td style="width: 131.25px">
<asp:Button ID="Button1" runat="server" CssClass="button" Text="Cancle" /></td>
<td style="width: 43.5px"> </td>
</tr>
<tr>
<td style="width: 43.5px"> </td>
<td style="width: 131.25px">
<asp:LinkButton ID="LinkButton1" runat="server">Forgot Password</asp:LinkButton>
</td>
<td style="width: 131.25px">
<asp:Button ID="Button3" runat="server" CssClass="button" Text="Sign Up" />
</td>
<td style="width: 43.5px"> </td>
</tr>
</table>
</div>
</div>
</asp:panel>
</div>
on button2_Click code behind is as follows.
protected void Button2_Click(object sender, EventArgs e)
{
ds = obj.sel("select UserName and Password from tblUserMaster where UserName='"+txtUserName.Text+"' AND Password='"+txtPassword.Text+"'");
if (ds.Tables[0].Rows.Count == 0)
{
Label3.Visible = true;
}
else
{
Response.Redirect("Default.aspx");
}
}
But when i'm clicking on LOGIN Button it is not redirection me on Default.aspx page popup is getting closed.
while on clicking on cancel button it is not working at all.
please suggest an solution as soon as possible.
use update panel for refreshing problem .
here is complete code .
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div class="wrapper">
<ul id="icons">
<li><asp:ImageButton runat="server" ImageUrl="images/lgn.png" ID="btnimg" CssClass="image" /></li>
</ul>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnimg" PopupControlID="Panel1" BackgroundCssClass="modalBackground" CancelControlID="Button1"></asp:ModalPopupExtender>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" CssClass="popup" runat="server">
<div class="popup">
<div id="PopupHeader" style="height: 55px; background-color: #f6f6f6; border-radius: 10px; width: 348px; font-size: 2.7em;"><font style="margin: 30px 0px 0px 20px; vertical-align: middle; color: Black; line-height: 1.2em; font-size: 37px; font-family: BonvenoCF;"> Login </font></div>
<div class="PopupBody">
<table width="350px" style="vertical-align: middle; text-align: center;">
<tr>
<td style="width: 43.5px"> </td>
<td style="width: 131.25px"> </td>
<td style="width: 131.25px"> </td>
<td style="width: 43.5px"> </td>
</tr>
<tr>
<td style="width: 43.5px"> </td>
<td style="width: 131.25px">
<asp:Label ID="Label1" runat="server" Text="User Name: "></asp:Label>
</td>
<td style="width: 131.25px">
<asp:TextBox ID="txtUserName" runat="server" Height="20px" Style="border-radius: 8px;"> </asp:TextBox>
</td>
<td style="width: 43.5px"> </td>
</tr>
<tr>
<td style="width: 43.5px"> </td>
<td style="width: 131.25px"> </td>
<td style="width: 131.25px"> </td>
<td style="width: 43.5px"> </td>
</tr>
<tr>
<td style="width: 43.5px"> </td>
<td style="width: 131.25px">
<asp:Label ID="Label2" runat="server" Text="Password: "></asp:Label>
</td>
<td style="width: 131.25px">
<asp:TextBox ID="txtPassword" runat="server" Height="20px" Style="border-radius: 8px;"> </asp:TextBox>
<asp:TextBoxWatermarkExtender ID="txtPassword_TextBoxWatermarkExtender"
runat="server" Enabled="True" TargetControlID="txtPassword"
WatermarkText="Password">
</asp:TextBoxWatermarkExtender>
</td>
<td style="width: 43.5px"> </td>
</tr>
<tr>
<td style="width: 43.5px"> </td>
<td colspan="2">
<asp:Label ID="Label3" runat="server" Text="Invalid User Name Or Password." Visible="False"></asp:Label>
</td>
<td style="width: 43.5px"> </td>
</tr>
<tr>
<td style="width: 43.5px"> </td>
<td style="width: 131.25px">
<asp:Button ID="Button2" runat="server" CssClass="button" Text="Login" OnClick="Button2_Click" />
</td>
<td style="width: 131.25px">
<asp:Button ID="Button1" runat="server" CssClass="button" Text="Cancle" /></td>
<td style="width: 43.5px"> </td>
</tr>
<tr>
<td style="width: 43.5px"> </td>
<td style="width: 131.25px">
<asp:LinkButton ID="LinkButton1" runat="server">Forgot Password</asp:LinkButton>
</td>
<td style="width: 131.25px">
<asp:Button ID="Button3" runat="server" CssClass="button" Text="Sign Up" OnClick="Button3_Click" />
</td>
<td style="width: 43.5px"> </td>
</tr>
</table>
</div>
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
#Chirag : you haven't added the onclick event on your button . so please add this ..
edit your code .
<asp:Button ID="Button2" runat="server" CssClass="button" Text="Login" OnClick="Button2_Click"/>

Update dropdownlist on a Panel

I have two dropDownLists in a Panel that pops up. When i change one value in the first dropDownList i want to populate the seconde dropDownList with the value chosen in the first dropDownList. Like i have AutoPostBack = "true" the page is always refreshing and the PopUp disappears. When in fact i only want to update the panel on the PopUp.
I´m using AsyncPostBackTrigger.
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup"
PopupControlID="pnlpopup" CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="199px" Width="400px"
Style="display: none">
<table width="100%" style="border: Solid 3px #D55500; width: 100%; height: 100%"
cellpadding="5" cellspacing="0">
<tr style="background-color: #D55500">
<td colspan="2" style="height: 10%; color: White; font-weight: bold; font-size: larger"
align="center">
Insert Product
</td>
</tr>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<tr>
<td align="right" style="width: 45%">
Category:
</td>
<td>
<asp:DropDownList AutoPostBack="true" runat="server" ID="DropDownList1" OnSelectedIndexChanged="dropDownList_Change" />
</td>
</tr>
<tr>
<td align="right">
Product:
</td>
<td>
<asp:DropDownList id="DropDownList2" runat="server">
</asp:DropDownList>
</td>
</tr>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<tr>
<td>
</td>
<td>
<asp:Label ID="popup_modo" runat="server" Visible="false"></asp:Label>
<asp:Button ID="btnCommand" CommandName="Update" runat="server" Text="Update" OnClick="btnUpdate_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
Try this:
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="199px" Width="400px"
Style="display: none">
<table width="100%" style="border: Solid 3px #D55500; width: 100%; height: 100%"
cellpadding="5" cellspacing="0">
<tr style="background-color: #D55500">
<td colspan="2" style="height: 10%; color: White; font-weight: bold; font-size: larger"
align="center">
Insert Product
</td>
</tr>
<tr>
<td align="right" style="width: 45%">
Category:
</td>
<td>
<asp:DropDownList AutoPostBack="true" runat="server" ID="DropDownList1" OnSelectedIndexChanged="dropDownList_Change" />
</td>
</tr>
<tr>
<td align="right">
Product:
</td>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList id="DropDownList2" runat="server">
</asp:DropDownList></ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Label ID="popup_modo" runat="server" Visible="false"></asp:Label>
<asp:Button ID="btnCommand" CommandName="Update" runat="server" Text="Update" OnClick="btnUpdate_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
I had the similar problem and the key was in the part where I set the Items do Dropdown. When you set these Items it select the first one after page reload (with autopostback).
If this is your problem try this:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillDropDown();
}
}

Categories