in aspx file when i change the postion of button its work well but when i put it in current psitiion the click method doesnot call;
the function of click is correct
button4(end of codes)
<div class="ui container">
<div runat="server" id="mydiv" class="ui form">
</div>
</div>
<button onclick="myFunction()">Click me</button>
<div class="ui modal">
<i class="close icon"></i>
<div class="header">
Add request
</div>
<div class="image content">
<div class="ui form">
<label>user id</label>
<input runat="server" id="usid" type="text" />
<label>Details</label>
<textarea id="details" runat="server" rows="2"></textarea>
<label>Cost</label>
<input id="cost" runat="server" type="text" />
<label>dead time</label>
<input id="date" runat="server" class="ui date" type="date" />
</div>
</div>
<div class="actions">
<asp:Button ID="Button4" class="ui positive right labeled icon button" runat="server" OnClick="Button4_Click" Text="Button" />
<i class="checkmark icon"></i>
</div>
</div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
i use ui-semantic popup
behind code
protected void Button4_Click(object sender, EventArgs e)
{
try
{
acceptance ac = new acceptance();
ac.user_id = Convert.ToInt32(usid.Value.ToString());
ac.work_id = mywork.id;
ac.detail = details.Value.ToString();
ac.dead_time = Convert.ToDateTime(date.Value.ToString());
DataClasses1DataContext db = new DataClasses1DataContext();
var hj = from i in db.acceptances where i.user_id == ac.user_id && i.work_id == ac.work_id select i;
if (hj.Count() > 0)
{
Exception c = new Exception("this user alredy accepted");
throw c;
}
var maxValue = db.acceptances.Max(x => x.id);
ac.id = maxValue + 1;
db.acceptances.InsertOnSubmit(ac);
db.SubmitChanges();
}
catch (Exception ex)
{
HtmlGenericControl er = (HtmlGenericControl)this.Master.FindControl("error");
HtmlGenericControl al = (HtmlGenericControl)this.Master.FindControl("alert");
al.Visible = true;
er.Visible = true;
er.InnerText = ex.Message;
}
}
Related
This is the aspx code for the controls The feature that I want over here is that when I enter the value for the textboxes and select a dropdown value.. only after that should the button be enabled else the button should be disabled.
<div id="div1" class="panel-collapse collapse in">
<div class="form-inline">
<div class="form-group">
<label class="control-label">Part Number:</label>
<asp:TextBox type="text" class="form-control" ID="itemOne" runat="server" />
</div>
<div class="form-group">
<label>Name:</label>
<asp:TextBox type="text" class="form-control" ID="itemTwo" runat="server" />
</div>
<div class="form-group">
<label>Price:</label>
<asp:TextBox type="text" class="form-control" ID="itemThree" runat="server" />
</div>
<div class="form-group">
<label>Weight:</label>
<asp:TextBox type="text" class="form-control" ID="itemFour" runat="server" Style="width: 100px" />
</div>
<div class="form-group">
<label>Quantity:</label>
<asp:TextBox type="text" class="form-control" ID="miscItemQuantity" runat="server" Style="width: 80px" />
</div>
<div class="form-group">
<asp:DropDownList ID="dropdownList" CssClass="form-control" runat="server" Width="150" />
<%-- Items are added dynamically from the codebehind --%>
</div>
<asp:Button runat="server" ID="addItem" type="submit" Text="Add Item" CssClass="btn btn-primary pull-right"></asp:Button>
</div>
</div>
This is the jQuery code that I have tried to enable and disable the button with just one textbox
$(document).ready(function () {
$("#<%=itemOne.ClientID%>").keyup(function () {
if ($(this).val().length > 2) {
$("#<%=addItem.ClientID%>").removeAttr('disabled');
}
else {
$("#<%=addItem.ClientID%>").attr('disabled', 'disabled');
}
}).trigger('keyup');
});
I will be very glad to receive any solutions.
I think you are looking for something like this. First add a listener to each TextBox and DropDownList in div1 to check for changes. Then validate all controls withing the div for the correct values and set the button visibility accordingly.
<script type="text/javascript">
$(document).ready(function () {
$("#div1 input[type='text']").keyup(function () {
checkValues();
});
$("#div1 select").change(function () {
checkValues();
});
checkValues()
});
function checkValues() {
var isValid = true;
$("#div1 input[type='text']").each(function () {
if ($(this).val().length < 2) {
isValid = false;
}
});
$("#div1 select").each(function () {
if ($(this).prop('selectedIndex') === 0) {
isValid = false;
}
});
if (isValid) {
$("#<%=addItem.ClientID%>").removeAttr('disabled');
}
else {
$("#<%=addItem.ClientID%>").attr('disabled', 'disabled');
}
}
</script>
I generating a listview (a list of products for user to make order) with a textbox inside. User may enter quantity of product that want to order in this textbox. I set the initial value of this textbox to 0. My issue is when user insert a new quantity value in this textbox and click submit button, it should retrieve the value that user insert, but it still retrieve the initial value which is 0. Below is my code, can anyone tell me which part of my code is incorrect?
HTML page
<div class="row">
<asp:Listview runat="server" ID="Listview1">
<ItemTemplate>
<div class="col-sm-6 col-md-4 col-lg-4" id="divRow">
<div class="wrap-listview-block">
<div class="listview-block-inner">
<div class="row">
<div class="col-xs-2 col-sm-3 col-md-3 col-lg-3">
<%--<img src="../images/img-product-gerbang-jingga.jpg">--%>
<telerik:RadBinaryImage runat="server" ID="RadBinaryImage1" DataValue='<%#Eval("ProductImg") %>' Width="80.02" Height="109.55"
AutoAdjustImageControlSize="false" ToolTip='<%#Eval("ProdCode", "Photo of {0}") %>'
AlternateText='<%#Eval("ProdCode", "Photo of {0}") %>' />
</div>
<div class="col-xs-10 col-sm-9 col-md-9 col-lg-9 listing-right">
<div class="caption">
<h3>(<%#Eval("ProdCode")%>) <%#Eval("ProdName")%> </h3>
<div class="btn-details">
<i class="fa fa-info-circle" aria-hidden="true"></i> <i class="fa fa-gift" aria-hidden="true"></i> <i class="fa fa-file-image-o" aria-hidden="true"></i> <i class="fa fa-book" aria-hidden="true"></i>
</div>
<div class="btn-details">
<form class="form-inline">
<%--<select class="form-control input-sm col-xs-6">
<option>Carton</option>
<option>Piece</option>
</select>--%>
<asp:DropDownList ID="ddlQuantity" runat="server" CssClass="form-control input-sm col-xs-6">
<asp:ListItem Value="1" Selected="True">Carton</asp:ListItem>
<asp:ListItem Value="2">Piece</asp:ListItem>
</asp:DropDownList>
<div class="input-group col-xs-6">
<span class="input-group-btn">
<asp:LinkButton runat="server" CssClass="btn btn-sm btn-sub" ID="btnDown"><i class="fa fa-minus" aria-hidden="true"></i></asp:LinkButton>
</span>
<asp:TextBox runat="server" ID="txtQuantity" CssClass="form-control input-sm text-right" Text="0" Width="90"></asp:TextBox>
<span class="input-group-btn">
<asp:LinkButton runat="server" CssClass="btn btn-sm btn-sub" ID="btnUp"><i class="fa fa-plus" aria-hidden="true"></i></asp:LinkButton>
</span>
<ajaxToolkit:NumericUpDownExtender ID="NumericUpDownExtender1" Runat="server" TargetControlID="txtQuantity" TargetButtonDownID="btnDown" TargetButtonUpID="btnUp"/>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div><!-- listing block -->
</div><!--Product block -->
</ItemTemplate>
</asp:Listview>
</div>
<div class="footer-bar">
<div class="row">
<div class="col-xs-12">
<asp:LinkButton runat="server" ID="btnProceedOrder" OnClick="btnProceedOrder_Click" >
<div class="footer-inner">
<span class='glyphicon glyphicon-shopping-cart' aria-hidden="true"></span>
<br />
<asp:Literal runat="server" ID="litProceedOrder" Text="<%$ Resources:Lang, ProceedOrder %>"></asp:Literal>
</div>
</asp:LinkButton>
</div>
</div>
</div>
Code Behind
protected void Page_Load(object sender, EventArgs e)
{
String UserName = Utils.Session.Get(Constants.SessionObjects.UserName);
if (!IsPostBack)
{
DataTable dt = this.GetData();
Listview1.DataSource = dt;
Listview1.DataBind();
}
}
private DataTable GetData()
{
string RetailLink = ConfigurationManager.ConnectionStrings["DefaultDB"].ConnectionString;
using (SqlConnection con = new SqlConnection(RetailLink))
{
using (SqlCommand cmd = new SqlCommand("EXEC sp_mProduct_Sel_ByPrincipalRetailer#PWA " + UserName + ", " + PricipalID.ToInt32()))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
return dt;
}
}
}
}
}
protected void btnProceedOrder_Click(object sender, EventArgs e)
{
foreach (ListViewDataItem row in Listview1.Items)
{
TextBox txtQuantity = row.FindControl("txtQuantity") as TextBox;
string Quantity = txtQuantity.Text.ToString(); //string Quantity keep getting "0", I need to get the value that user insert.
}
}
I am trying to enable show/hide password feature. I am creating an asp.net web form using C#.
My code is as below,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class show : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox1.Checked == false)
{
TextBox1.TextMode = TextBoxMode.Password;
}
if (CheckBox1.Checked == true)
{
TextBox1.TextMode = TextBoxMode.SingleLine;
}
}
}
On mypage.aspx,
there is a checkbox whose autopostback property is true and a textbox whose textmode is password.
The expected result is:-
show password into text when checkbox is checked.
hide password when checkbox is unchecked.
The problem is :-
This code is working only once i.e. it is not being executed when checkbox is checked or unchecked again.
The textbox becomes blank.
Please help me soon.
You are losing value within TextBox because on selection change, the page loads again, you need to check whether its a postBack or first time load and set the textBox value.
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string Password = TextBox1.Text;
TextBox1.Attributes.Add("value", Password);
}
}
Your problem will be solved. I've tested it.
Hope it helps!
There's exactly zero need to use a postback for this. An example using jQuery:
Markup:
<label>Password fields are just a UI convenience:</label>
<input type="password" id="password" value="super secret password" />
<label>
<input type="checkbox" id="toggle-password" /> Toggle
</label>
jQuery code:
$(function() {
$('#toggle-password').on('change', function(e) {
var _this = $(this);
if (_this.is(':checked')) {
$('#password').attr({
'type': 'text'
});
} else {
$('#password').attr({
'type': 'password'
});
}
})
});
A vanilla JS version:
var toggle = document.getElementById('toggle-password');
var textbox = document.getElementById('password');
toggle.addEventListener("click", function() {
var isChecked = toggle.checked;
if (isChecked) {
textbox.type = "text";
} else {
textbox.type = "password";
}
})
You can't set the text property of a Password Type field for security reasons.So another way to set the value after changing mode is
if (CheckBox1.Checked == false)
{
string pass = TextBox1.Text;
TextBox1.TextMode = TextBoxMode.Password;
TextBox1.Attributes.Add("value", pass);
}
if (CheckBox1.Checked)
{
TextBox1.TextMode = TextBoxMode.SingleLine;
}
<head runat="server">
<title>Show Hide Password</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#show_password').hover(function show() {
//Change the attribute to text
$('#txtCurrentpassword').attr('type', 'text');
$('.icon').removeClass('fa fa-eye-slash').addClass('fa fa-eye');
},
function () {
//Change the attribute back to password
$('#txtCurrentpassword').attr('type', 'password');
$('.icon').removeClass('fa fa-eye').addClass('fa fa-eye-slash');
});
//CheckBox Show Password
$('#ShowPassword').click(function () {
$('#Password').attr('type', $(this).is(':checked') ? 'text' : 'password');
});
});
</script>
<script type="text/javascript">
$(document).ready(function () {
$('#show_password1').hover(function show() {
//Change the attribute to text
$('#txtNewPassword').attr('type', 'text');
$('.icon').removeClass('fa fa-eye-slash').addClass('fa fa-eye');
},
function () {
//Change the attribute back to password
$('#txtNewPassword').attr('type', 'password');
$('.icon').removeClass('fa fa-eye').addClass('fa fa-eye-slash');
});
//CheckBox Show Password
$('#ShowPassword').click(function () {
$('#Password').attr('type', $(this).is(':checked') ? 'text' : 'password');
});
});
</script>
<script type="text/javascript">
$(document).ready(function () {
$('#show_password2').hover(function show() {
//Change the attribute to text
$('#txtConfirmPassword').attr('type', 'text');
$('.icon').removeClass('fa fa-eye-slash').addClass('fa fa-eye');
},
function () {
//Change the attribute back to password
$('#txtConfirmPassword').attr('type', 'password');
$('.icon').removeClass('fa fa-eye').addClass('fa fa-eye-slash');
});
//CheckBox Show Password
$('#ShowPassword').click(function () {
$('#Password').attr('type', $(this).is(':checked') ? 'text' : 'password');
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<br />
<br />
<br />
<div class="col-md-10">
<div class="" style="display: none" runat="server" id="divStatusMsg">
<asp:HiddenField ID="lblLoginUserId" runat="server" />
<asp:HiddenField ID="HidEncrptedPWD" runat="server" />
<asp:HiddenField ID="HidCurrEncrptedPWD" runat="server" />
<asp:HiddenField ID="hidError" runat="server" />
</div>
</div>
<h2>Update Password</h2>
<label class="col-form-label" style="color: red">(Min 10 Character including 1 Upper, 1 Lower Charcter, 1 Numeric & 1 Special Character)</label>
<div class="row">
<div class="col-md-6">
<label>User Name</label>
<div class="input-group">
<asp:TextBox ID="txtUserName" TextMode="SingleLine" runat="server" CssClass="form-control" Enabled="false"></asp:TextBox>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label>Current Password</label>
<div class="input-group">
<asp:TextBox ID="txtCurrentpassword" TextMode="Password" runat="server" CssClass="form-control"></asp:TextBox>
<div class="input-group-append">
<button id="show_password" class="btn btn-primary" type="button">
<span class="fa fa-eye-slash icon"></span>
</button>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label>New Password</label>
<div class="input-group">
<asp:TextBox ID="txtNewPassword" TextMode="Password" runat="server" CssClass="form-control"></asp:TextBox>
<div class="input-group-append">
<button id="show_password1" class="btn btn-primary" type="button">
<span class="fa fa-eye-slash icon"></span>
</button>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label>Re-Enter Password :</label>
<div class="input-group">
<asp:TextBox ID="txtConfirmPassword" TextMode="Password" runat="server" CssClass="form-control"></asp:TextBox>
<div class="input-group-append">
<button id="show_password2" class="btn btn-primary" type="button">
<span class="fa fa-eye-slash icon"></span>
</button>
</div>
</div>
</div>
</div>
<br />
<!--Button Region-->
<div class="row">
<div class="col-lg-6 text-right" id="divDateSearch">
<div class="form-group">
<button type="button" id="btnSave" runat="server" class="btn btn-success btn-border btn-sm" onserverclick="btnSave_click">Change</button>
<button type="button" id="btnReset" runat="server" class="btn btn-default btn-border btn-sm" onserverclick="btnReset_click">Reset</button>
</div>
</div>
</div>
<!--Button Region-->
</div>
</form>
</body>
Why button doesn't hit the event ? I put a breakpoint, started with debugging but when I click it doesn't hit the event but other buttons does ? Why ?
I have also posted complete code in case you want to take a look at it.
event:
protected void btnUpdate_Click(object sender, EventArgs e)
{
try
{
if (IsPostBack && Page.IsValid)
{
if (string.IsNullOrEmpty(txtBoxContractorTypeName.Text))
{
ResultLabel.ResultLabelAttributes("Fill the required fields !", ProjectUserControls.Enums.ResultLabel_Color.Red);
return;
}
byte ID = Convert.ToByte(HdnFieldContractorTypeID.Value);
string ContractorTypeName = txtBoxContractorTypeName.Text;
if (MngContractorTypes.UpdateContractorTypes(ID, ContractorTypeName))
{
txtBoxContractorTypeName.Text = "";
ShowContractorTypes();
ResultLabel.ResultLabelAttributes("Record updated successfully !", ProjectUserControls.Enums.ResultLabel_Color.Green);
}
else
{
ResultLabel.ResultLabelAttributes("Failed !", ProjectUserControls.Enums.ResultLabel_Color.Red);
}
}
}
catch (Exception) { }
finally
{
ResultPanel.Controls.Add(ResultLabel);
}
}
Button:
<asp:Button ID="btnUpdate" ValidationGroup="0" runat="server" CssClass="btn btn-warning"
Text="Update" OnClick="btnUpdate_Click" />
Complete code:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:UpdateProgress AssociatedUpdatePanelID="UpdatePanel1" runat="server" ID="UpdateProgress1">
<ProgressTemplate>
<div class="ajax-loading">
<div></div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="page-content">
<div class="row">
<div class="col-lg-12">
<center>
<asp:Panel ID="ResultPanel" runat="server">
</asp:Panel>
</center>
</div>
<div class="col-md-6">
<div class="panel">
<div class="panel-header bg-primary">
<h3><i class="fa fa-book"></i>Add Contractor Type</h3>
</div>
<div class="panel-content">
<div class="col-md-12">
<div class="col-md-6">
<div class="form-group">
<label class="control-label">
Contractor Type
<asp:HiddenField ID="HdnFieldContractorTypeID" runat="server" />
</label>
<asp:TextBox runat="server" ID="txtBoxContractorTypeName" CssClass="form-control"></asp:TextBox>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-footer clearfix">
<div class="pull-right">
<input type="button" value="Reset" onclick="Clear()" class="btn btn-success" />
<asp:Button ID="btnAddContractorType" ValidationGroup="0" runat="server" CssClass="btn btn-primary"
Text="Add" OnClick="btnAddContractorType_Click" />
<asp:Button ID="btnUpdate" runat="server" CssClass="btn btn-warning"
Text="Update" OnClick="btnUpdate_Click" Visible="false" />
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel fadeIn">
<div class="panel-header bg-success">
<h3><i class="fa fa-search"></i>Contractor Types</h3>
</div>
<div class="panel-content">
<div class="col-md-12">
<div class="input-group">
<label class="control-label">
Search
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Required" ForeColor="Red" ControlToValidate="txtSearch" ValidationGroup="S"></asp:RequiredFieldValidator>
</label>
<asp:TextBox runat="server" CssClass="form-control" ID="txtSearch"></asp:TextBox>
<span class="input-group-btn">
<asp:Button runat="server" ID="btnSearch" OnClick="btnSearch_Click" CssClass="btn btn-warning" Text="Search" Style="margin-top: 25px" ValidationGroup="S" />
</span>
</div>
</div>
<div class="col-md-12">
<asp:GridView runat="server" ID="grdviewContractorTypes" OnRowEditing="grdviewContractorTypes_RowEditing" OnRowCommand="grdviewContractorTypes_RowCommand" DataKeyNames="pk_ContractorTypes_ContractorTypeID" AutoGenerateColumns="false" CssClass="table table-condensed table-bordered table-striped table-responsive">
<Columns>
<asp:BoundField DataField="pk_ContractorTypes_ContractorTypeID" HeaderText="ID" />
<asp:BoundField DataField="ContractorTypeName" HeaderText="Contractor Type" />
<asp:ButtonField CommandName="edit" ImageUrl="~/assets/global/images/shopping/edit.png" ButtonType="Image" ControlStyle-Width="25px" ControlStyle-Height="25px" />
</Columns>
</asp:GridView>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
Server 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 Contractors;
public partial class MainForms_ContractorTypes : System.Web.UI.Page
{
ASP.controls_resultlabel_ascx ResultLabel = new ASP.controls_resultlabel_ascx();
Contractors.ManageContractorTypes MngContractorTypes = new ManageContractorTypes();
protected void Page_Load(object sender, EventArgs e)
{
//ASP.controls_resultlabel_ascx ResultLabel = new ASP.controls_resultlabel_ascx();
if (!IsPostBack)
{
}
}
protected void btnAddContractorType_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(txtBoxContractorTypeName.Text))
{
ResultLabel.ResultLabelAttributes("Fill the required fields !", ProjectUserControls.Enums.ResultLabel_Color.Red);
return;
}
string ContractorTypeName = txtBoxContractorTypeName.Text;
if (MngContractorTypes.InsertContractorTypes(ContractorTypeName))
{
txtBoxContractorTypeName.Text= "";
ResultLabel.ResultLabelAttributes("Record inserted successfully !", ProjectUserControls.Enums.ResultLabel_Color.Green);
}
else
{
ResultLabel.ResultLabelAttributes("Account Already Exist !", ProjectUserControls.Enums.ResultLabel_Color.Red);
}
}
catch (Exception)
{
}
finally
{
ResultPanel.Controls.Add(ResultLabel);
}
}
protected void grdviewContractorTypes_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
if (e.CommandName == "edit")
{
byte ContractorTypeID = Convert.ToByte(grdviewContractorTypes.DataKeys[Convert.ToInt32(e.CommandArgument)].Value);
//HFActID.Value = ID.ToString();
btnAddContractorType.Visible = false;
btnUpdate.Visible = true;
DataTable dt = MngContractorTypes.SelectContractorTypesByContractorTypeID(ContractorTypeID);
DataRow r = dt.Rows[0];
txtBoxContractorTypeName.Text = r["ContractorTypeName"].ToString();
HdnFieldContractorTypeID.Value = r["pk_ContractorTypes_ContractorTypeID"].ToString();
//txtSearch.Text = "Testing...";
//Response.Write("DONE");
}
}
catch (Exception ex)
{
Response.Write(Convert.ToString(ex.Message));
}
}
protected void grdviewContractorTypes_RowEditing(object sender, GridViewEditEventArgs e)
{
// code to edit
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(txtBoxContractorTypeName.Text))
{
ResultLabel.ResultLabelAttributes("Fill the required fields !", ProjectUserControls.Enums.ResultLabel_Color.Red);
return;
}
byte ID = Convert.ToByte(HdnFieldContractorTypeID.Value);
string ContractorTypeName = txtBoxContractorTypeName.Text;
if (MngContractorTypes.UpdateContractorTypes(ID, ContractorTypeName))
{
txtBoxContractorTypeName.Text = "";
ShowContractorTypes();
ResultLabel.ResultLabelAttributes("Record updated successfully !", ProjectUserControls.Enums.ResultLabel_Color.Green);
}
else
{
ResultLabel.ResultLabelAttributes("Failed !", ProjectUserControls.Enums.ResultLabel_Color.Red);
}
}
catch (Exception) { }
finally
{
ResultPanel.Controls.Add(ResultLabel);
}
}
private void ShowContractorTypes()
{
grdviewContractorTypes.DataSource = MngContractorTypes.SelectContractorTypes();
grdviewContractorTypes.DataBind();
}
protected void btnSearch_Click(object sender, EventArgs e)
{
try
{
DataTable dt = MngContractorTypes.SelectContractorTypesByContractorTypeName(txtSearch.Text.Trim());
if (dt.Rows.Count > 0)
{
grdviewContractorTypes.DataSource = dt;
grdviewContractorTypes.DataBind();
}
else
{
grdviewContractorTypes.EmptyDataText = "No Record Found";
grdviewContractorTypes.DataBind();
}
}
catch (Exception) { }
}
}
Have you copied this method from other page/application ?
If yes then it will not work.
You need to delete the event and event name assigned to the button then go to design view and go to button event properties go to onClick event double click next to it, it will generate event and it automatically assigns event name to the button.
If No,
Try to Clean your solution and then try once again.
Please refer this article
Try changing the access modifier from protected to public, this will stop the method from being called depending on your class structure.
See here for more information on access modifiers: https://msdn.microsoft.com/en-us/library/ms173121.aspx
Try enabling the AutoPostBack property of the Button.
<asp:Button ID="btnUpdate" ValidationGroup="0" runat="server" CssClass="btn btn-warning" Text="Update" OnClick="btnUpdate_Click" AutoPostBack="true" />
In my Dropdownlist Selected index change event not firing.Here i use auto post back true &
View state also true.But Selected Index Changed Event not firing
My Code
<%# Page Language="C#" AutoEventWireup="true" CodeFile="AdminEagleViewLogin.aspx.cs" Inherits="AdminEagleViewLogin" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<style>
body{padding-top:20px;}
</style>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<div class="row">
User : <asp:DropDownList ID="drpusr" runat="server" Visible="true" OnSelectedIndexChanged="drpusr_SelectedIndexChanged" AutoPostBack="true" EnableViewState="true" ></asp:DropDownList>
Password: <asp:Label ID="lbluserpw" runat="server"></asp:Label>
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Please sign in</h3>
</div>
<div class="panel-body">
<form accept-charset="UTF-8" role="form">
<fieldset>
<div class="form-group">
<asp:TextBox ID="txtusr" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<asp:TextBox ID="txtpw" runat="server" TextMode="Password"></asp:TextBox>
</div>
<div class="checkbox">
<label>
<input name="remember" type="checkbox" value="Remember Me"> Remember Me
</label>
</div>
<asp:CheckBox ID="chkremember" runat="server" Visible="false" class="remchkbox" />
<asp:Button ID="submit" runat="server" class="btn btn-lg btn-success btn-block" Text="Submit" OnClick="submit_Click" />
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
ServerSide
User bind to Dropdown is working.
public partial class AdminEagleViewLogin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BindUsers();
//lbluserpw.Text = Membership.Provider.GetPassword(drpusr.SelectedValue, String.Empty);
}
protected void submit_Click(object sender, EventArgs e)
{
if (Membership.ValidateUser(txtusr.Text, txtpw.Text))
{
FormsAuthentication.SetAuthCookie(txtusr.Text, chkremember.Checked);
string[] CurrentUserRole = Roles.GetRolesForUser(txtusr.Text);
var admin = "Administrator";
var manager = "Manager";
var user = "User";
if (CurrentUserRole.Contains(admin))
{
Response.Redirect("Administrator.aspx");
}
else if (CurrentUserRole.Contains(manager))
{
Response.Redirect("Manager.aspx");
}
else
{
Response.Redirect("UserPage.aspx");
}
}
else
{
Response.Redirect("AdminEagleViewLogin.aspx");
}
}
protected void BindUsers()
{
DataAccess da = new DataAccess();
drpusr.DataSource = da.GetUsers();
drpusr.DataTextField = "UserName";
drpusr.DataValueField = "UserId";
drpusr.DataBind();
drpusr.Items.Insert(0, new ListItem("-- Select User --", "0"));
drpusr.Items.RemoveAt(1);
}
protected void drpusr_SelectedIndexChanged(object sender, EventArgs e)
{
lbluserpw.Text = Membership.Provider.GetPassword(drpusr.SelectedValue, String.Empty);
}
}
Try this:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindUsers();
}
}
You shouldn't put a form element inside another form:
<form accept-charset="UTF-8" role="form">
<fieldset>
...
<asp:Button ID="submit" runat="server" class="btn btn-lg btn-success btn-block" Text="Submit" OnClick="submit_Click" />
</fieldset>
</form>
remove the inner form.
[Update]
Another problem is the "ID" property of the button.
change it to something else, other than "submit".