I have created a dialog box that open up from the aspx page. The dialog box contains information along with the buttons on the footer. MERGE and Close.
Below is the dialog box that I used for opening. This is successfully getting created and information a getting populated. However, when I am clicking on the "MERGE" button of the dialog box it does nothing as navigation is not transferred to the code behind file.
I have successfully defined the Click event on my code behind, but I don't understand why it is not firing it.
aspx page
<div class="modal-dialog" id="updateConfirmPopUp" style="display: none">
<div class="modal-content">
<div class="modal-header" id="popUpHeader">
<button type="button" class="close closePopup">
<span>×</span></button>
</div>
<div class="modal-body" id="confirmData">
<div id="random"></div>
<div class="dataTable_wrapper">
<div class="table-responsive">
<uc:ReviewGroupGrids ID="reviewGroupCtrls" runat="Server" />
</div>
</div>
</div>
<div class="modal-footer">
<asp:Button ID="Button1" runat="server" Text="Review Next" OnClick="btnMerge_Click" />
<button type="button" id="btnClosePopUp" class="btn btn-default closePopup">
Okay</button>
</div>
</div>
</div>
aspx.cs page
protected void btnMerge_Click(object sender, EventArgs e)
{
try
{
// SessionUtility.SetSession(Constants.LASTREVIEWGROUPIDPROCESSED, this.ReviewGroup.ReviewGroupId);
if (preventEvents)
{
Response.Redirect(Request.RawUrl, false);
return;
}
// ensure no action taken on current review group(partially or completly)
#region Handle review group for completly processed case
var selectedAssignment = SessionUtility.GetSession(Constants.SELECTEDUSERASSIGNMENT) as Assignment;
var currentReviewGroupID = hdnReviewGroupID.Value.ToString();
if (currentReviewGroupID != selectedAssignment.ReviewGroupId)
{
selectedAssignment.ReviewGroupId = currentReviewGroupID;
SessionUtility.SetSession(Constants.SELECTEDUSERASSIGNMENT, selectedAssignment);
LoadNextReviewGroup(null, null);
lblPreviousReviewGroupId.Text = string.Format(StaticConstants.REVIEWGROUPVALIDATIONMESSAGE, currentReviewGroupID);
lblPreviousReviewGroupId.Visible = true;
return;
}
#endregion
if (!string.IsNullOrEmpty(selectedIds))
{
SessionUtility.SetSession(Constants.USERSERLECTIONROWIDS, selectedIds);
if (BtnMerge_Click != null)
{
BtnMerge_Click(sender, e);
}
Response.Redirect("MergeGroup.aspx", false);
}
}
catch (Exception ex)
{
SessionUtility.SetSession(Constants.Error, ex);
NavigationHelper.ToErrorPage(false);
}
}
My client click event is working fine.The only problem is with the onClick event.
An HTML Button can't call server side code. You have to use asp button with the runat="server" tag. something like
<asp:Button ID="btnMerge" runat="server" Text="MERGE" OnClick="btnMerge_Click" />
Related
This is my markup:
<%# Page Title="" Language="C#" MasterPageFile="~/User/Default.Master" AutoEventWireup="true" CodeBehind="Consulation.aspx.cs" Inherits="PetShop.User.Consulation" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script>
window.onload = function () {
var second = 5;
setTimeout(function () {
document.getElementById("<%=lblMsg.ClientID%>").style.display = "none";
}, second * 1000)
}
</script>
<link href="../CSSandJS/StyleCss/consulation.css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<!-- Slider -->
<section id="Slider">
<div class="aspect-ratio-169">
<img src="../CSSandJS/images/bg_1.jpg" alt="">
<img src="../CSSandJS/images/bg_2.jpg" alt="">
<img src="../CSSandJS/images/bg_3.jpg" alt="">
<img src="../CSSandJS/images/bg_4.jpg" alt="">
</div>
<div class="dot-container">
<div class="dot active"></div>
<div class="dot"></div>
<div class="dot"></div>
<div class="dot"></div>
</div>
</section>
<!-- End Slider -->
<!-- Free Consulation -->
<section class="contact">
<div class="container-contact">
<h1>Đặt lịch hẹn</h1>
<div class="row">
<div class="contact-img">
<img src="../CSSandJS/images/bg_1.jpg" alt="" width="400">
</div>
<div class="input-infor">
<div class="form">
<div class="dbl-field">
<asp:DropDownList ID="ddlCategory" runat="server" CssClass="form-control option field-mail listOp" DataSourceID="SqlDataSource1" DataTextField="TENDV" DataValueField="MADV" AppendDataBoundItems="true">
<asp:ListItem Value="0">Chọn danh mục</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:cs %>" SelectCommand="SELECT [MADV], [TENDV] FROM [DICHVU]"></asp:SqlDataSource>
</div>
<div class="dbl-field">
<div class="field-mail">
<asp:TextBox ID="txtEmail" runat="server" CssClass="form-control input" placeholder="Nhập email" required></asp:TextBox>
<i class="ri-mail-line"></i>
</div>
</div>
<div class="dbl-field">
<div class="field">
<asp:TextBox ID="txtNameAcc" runat="server" CssClass="form-control input" placeholder="Nhập tên"></asp:TextBox>
<i class="ri-user-line"></i>
</div>
<div class="field">
<asp:TextBox ID="txtSDT" runat="server" CssClass="form-control input" placeholder="Nhập số điện thoại" MaxLength="11"></asp:TextBox>
<i class="ri-phone-line"></i>
</div>
</div>
<div class="dbl-field">
<div class="field">
<asp:TextBox ID="txtNgay" runat="server" CssClass="form-control input" TextMode="Date"></asp:TextBox>
<i class="ri-calendar-2-line"></i>
</div>
<div class="field">
<asp:TextBox ID="txtTime" runat="server" CssClass="form-control input" placeholder="Nhập giờ hẹn" MaxLength="5" TextMode="SingleLine"></asp:TextBox>
<i class="ri-time-line"></i>
</div>
</div>
<div class="message">
<asp:TextBox ID="txtDescription" runat="server" CssClass="form-control textarea" placeholder="Tin nhắn" TextMode="MultiLine"></asp:TextBox>
<i class="ri-message-2-line"></i>
</div>
<div class="button-area">
<asp:Button ID="Add" runat="server" Text="Gửi lịch hẹn" class="btn btn-primary button" OnClick="Add_Click"/>
<asp:Label ID="lblMsg" runat="server" Visible="false"></asp:Label>
<%--<asp:linkbutton id="submitcal" runat="server" cssclass="btn btn-primary button" OnClick="Add_Click">gửi lịch hẹn</asp:linkbutton>--%>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- End Free Consulation -->
</asp:Content>
The textbox doesn't get any value when I debug the program.
I have tested the stored procedure in SQL Server and it works fine. But the data returned from the SQL code is empty.
My button submit code:
namespace PetShop.User
{
public partial class Consulation : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
}
private void clear()
{
txtEmail.Text = string.Empty;
txtDescription.Text = string.Empty;
txtNameAcc.Text = string.Empty;
txtSDT.Text = string.Empty;
txtNgay.Text = string.Empty;
txtTime.Text = string.Empty;
ddlCategory.ClearSelection();
}
protected void Add_Click(object sender, EventArgs e)
{
string actionName = string.Empty;
bool isValidToExcute = true;
con = new SqlConnection(Connection.GetConnectionString());
cmd = new SqlCommand("Add_KHaddLH", con);
cmd.Parameters.AddWithValue("#Action", "INSERT4KH");
cmd.Parameters.AddWithValue("#MaDv", ddlCategory.SelectedValue);
cmd.Parameters.AddWithValue("#EMail", txtEmail.Text.Trim());
cmd.Parameters.AddWithValue("#Ten", txtNameAcc.Text.Trim());
cmd.Parameters.AddWithValue("#Sdt", txtSDT.Text.Trim());
cmd.Parameters.AddWithValue("#NgayHen", txtNgay.Text.ToString());
cmd.Parameters.AddWithValue("#GioHen", txtTime.Text.Trim());
cmd.Parameters.AddWithValue("#GhiC", txtDescription.Text.Trim());
if (isValidToExcute)
{
cmd.CommandType = CommandType.StoredProcedure;
try
{
con.Open();
cmd.ExecuteNonQuery();
actionName = "gửi";
lblMsg.Visible = true;
lblMsg.Text = "Lịch hẹn " + actionName + " thành công!";
lblMsg.CssClass = "alert alert-success";
clear();
}
catch (Exception ex)
{
lblMsg.Visible = true;
lblMsg.Text = "Lỗi !!!" + ex.Message;
lblMsg.CssClass = "alert alert-danger";
}
finally
{
con.Close();
}
}
}
}
}
I think the error lies in the page reload, because when submitting it will delete all the data in the textbox and then enter.
I've tried adding some commands to the button but still can't handle that it keeps losing textbox data.
I update code behind and markup.
Support me,
Thank.
Ok, so that helps a boatload.
if we have this code:
protected void Add_Click(object sender, EventArgs e)
{
string actionName = string.Empty;
bool isValidToExcute = true;
Debug.Print(txtEmail.Text);
output:
So, you might want to put a break point in, or simple add some debug.prints, and see which text box controls are "empty". But, just looking at what you have, those text boxes should be ok.
And including page-load, shows that you not say running the "clear" routine you have. (so, having included the page load event eliminates about 100 possible issues here. This is VERY much why posting some of your code allows the public here to eliminate a 100 "back and forth" suggestions.) So, for example, had you included "clear" routine in page load, then of course page load fires each and every time BEFORE a button click event, so code in page load is VERY OFTEN suspect here. But, since you don't have code in page load event, we scratch that off the table.
So, far, the controls look to have values, but I suggest you add a break point, or some debug.prints as per above to be 100% sure that the controls in fact do not have values.
Also, just pasting in some of the markup, we see things like this:
So, you do have stray "garbage" in a number of places. (not good).
As it stands, with the posted markup, I MOST certainly do get/see/have/enjoy/observe that the text boxes are intact, do have values.
Given we can't re-produce your issue?
I suggest creating a blank new page, drop in some of those controls, and try a test button - (don't even bother with the database save code - we NOT gone that far down the debugging road just yet).
So, only thing so far?
Are you 100% sure the text boxes don't have values, and you tested this BEFORE any of the database save code runs?
and do remove the stray "required" markup in that txtEmail box, the editor even HONKS OUT AT YOU that the markup is bad as per above screen shot.
In fact, drop in another button on the form, and its only job would be to debug print out the text boxes - does that work?
As it stands now, you don't have a re-producable error, and the community in general here has not, does not see your error, nor are we the viewing public EVEN able to re-produce that these text boxes don't have values.
As a result, there information we don't have to re-produce the error.
I suggest building a page with just the txtEmail that is blank, and a simple button. if that works, then start adding markup from that other page until it stops working, since we here can't re-produce your issue with the provided code and markup you have provided.
And, since you using a master page, then check if page load in master page has any code that runs on page load.
I'm new at ASP.NET and web programming in general, here's my issue.
I have this DIV in my .aspx:
<div class="login">
<input type="text" placeholder="Usuário" name="usuario" id="usuario" runat="server"><br>
<input type="password" placeholder="Senha" name="senha" id="senha" runat="server"><br>
<button type="submit" class="btn-sucess" id="btn" runat="server" onserverclick="btn_Click" onclick="btn_Click">Login</button>
<h1 id="lbl1" runat="server" visible="false">Sucess</h1>
</div>
If the user clicks on the submit button it should be visible as it's written here in my aspx.cs
protected void btn_Click(object sender, EventArgs e)
{
lbl1.Visible = true;
}
Nothing happens. Why it doesn't work?
You're setting it to Visible false when rendering the control. Remove the visible property from aspx code and handle it in Page_Load event. All controls need to be inside form.
aspx
<form runat="server">
<div class="login">
<input type="text" placeholder="Usuário" name="usuario" id="usuario" runat="server"><br>
<input type="password" placeholder="Senha" name="senha" id="senha" runat="server"><br>
<button type="submit" class="btn-sucess" id="btn" runat="server" onserverclick="btn_Click" onclick="btn_Click">Login</button>
<h1 id="lbl1" runat="server">Sucess</h1>
</div>
</form>
Code-Behind
protected void Page_Load(object sender, EventArgs e)
{
lbl1.Visible = false;
}
With button click
protected void btn_Click(object sender, EventArgs e)
{
lbl1.Visible = true;
}
Also, if you want to handle anything at a client side, then alone use a javascript function btn_Click. But make sure that returns true and so the form will be submitted to the server.
Something like this,
Javascript
<script type="text/javascript">
function btn_Click()
{
return true;
}
</script>
I have created a dialog box that calls a user Control for creating a grid and populating it respectively. but this user control is used earlier, so when I am showing the dialog box, it is showing me the same grid. So, in order to call the user control again, i want its load event to get fired again. Is it possible to do this. Below is my code:
HTML
<%# Register TagPrefix="uc" TagName="ReviewGroupGrid" Src="UserControls/ReviewGroupGrid.ascx" %>
<%# Register TagPrefix="uc" TagName="ReviewGroupGrids" Src="UserControls/ReviewGroupGrid.ascx" %>
<%# Register Assembly="OCM.Phoenix.WebToolsFramework.Server.Modules.DataSteward.WebExtensions" Namespace="OCM.Phoenix.WebToolsFramework.Server.Modules.DataSteward.WebExtensions" TagPrefix="cc1" %>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="DataStewardContent">
<cc1:Button ID="btnMerge" runat="server" Text="Merge & Edit" OnClick="btnMerge_Click"
OnClientClick="javascript:return reviewGroupForm.getSelectedRowsForMerge()" />
<div class="modal-dialog" id="updateClaimConfirmPopUp" style="display: none">
<div class="modal-content">
<div class="modal-header" id="popUpHeader">
<button type="button" class="close closeClaimPopUp">
<span>×</span></button>
</div>
<div class="modal-body" id="confirmData">
<div id="random"></div>
<div class="dataTable_wrapper">
<div class="table-responsive">
<uc:ReviewGroupGrids ID="reviewGroupCtrls" runat="Server" />
</div>
</div>
</div>
<div class="modal-footer">
<asp:LinkButton ID="claimMerge" CssClass="buttonClassClaim btn btn-primary" runat="server" Text="Accept" OnClick="btnMerge_Click"/>
<button type="button" id="btnClosePopUp" class="buttonClassClaim btn btn-primary closeClaimPopUp">
Discard</button>
</div>
</div>
</div>
</asp:Content>
jQuery
getSelectedRowsForMerge: function () {
var entityType = $("input[id*='hdnEntityType']").val();
if (entityType === "19") {
$('#popUpHeader').find('h4').remove();
$('#random').find('h4').remove();
$('#popUpHeader').append(' <h4 class="modal-title" > ' + 'Need Your' + ' Attention!</h4>');
$('#random').append('<h4><b> ' + 'The Claims that you are merging are associated with different patients, merging the claims will result in explicit merging of the associated Patients as well, Please review the patient(s) details shown below before merging the claim' + '</b></h4>');
//$('#confirmData').append('<div class="table-responsive"').append(' <uc:ReviewGroupGrid ID="reviewGroupCtrl" runat="Server" />').append('</div>');
$("#updateClaimConfirmPopUp").dialog({
autoOpen: true,
width: 1600,
resizable: false,
draggable: true,
modal: true,
show: { effect: 'blind' }
});
}
},
When my dialog box is getting created, it is creating the user control but this user control is already populated. I want to call its load event so that the user control processes again. Can i do this via click event when opening the dialog?
Do you want the btnMerge to refresh the div everytime its shown. If so then you need to get the data from server via ajax call in your getSelectedRowsForMerge which can update the data shown in your ReviewGroupGrids control. In the success handler of this promise, set the popup to be shown and not immediately. This will refresh everything in the div and not require any server side load event
Snippet as follows, please add real code
getSelectedRowsForMerge: function () {
// various cleanups as present
$.ajax(...)
.success( function() {
//show the div
$("#updateClaimConfirmPopUp").dialog({ .... } );
})
I have Form tag in my layout page. I cant use form tags in content page, so I am using Form method="post" how to create button click event for this and how to give validation for html input type?
<form class="contact-form-title white" method="post">
<label id="lblFirstName" runat="server" title="First Name:">First Name:</label>
<input type="text" id="txtFirstNam" runat="server" /><br />
<label id="lblLastName" runat="server" title="Last Name:">Last Name:</label>
<input type="text" id="txtLastNam" runat="server" /><br />
<label id="lblEmail" runat="server" title="Email ID:">Email ID:</label>
<input type="text" id="txtEmail" runat="server" />
<label id="lblMessage" runat="server" title="Message">Message:</label>
<textarea id="txtMessag" runat="server" ></textarea><br />
<input type="submit" class="btn delicious f-center" runat="server" id="btnContac" name="SUBMIT" onserverclick="btnContac_Click" style="height:25%; width:10%;"/>
</form>
Back-End :
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnContac_Click(object sender, EventArgs e)
{
string FirstName = txtFirstNam.Value;
string LastName = txtLastNam.Value;
string EmailID = txtEmail.Value;
string Message = txtLastNam.Value;
}
Approach 1 : client side control
In Code behind use ispostback to catch the post back event,
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// write form population code;
}
else
{
//you will get posted data here;
}
}
to validate on client side, write your own java script validator something on below line.
<script type="text/javascript">
function validate()
{
var Firstname = document.getElementById('txtFirstNam').value
if (Firstname == "")
{
alert("Enter First Name");
return false;
}
if (LastName == "") {
alert("Enter Last Name");
return false;
}
}
</script>
then call this validator on submit button click
<input type="submit" class="btn delicious f-center" runat="server" id="btnContac" name="SUBMIT" onclick="return validate();" style="height:25%; width:10%;"/>
Option 2 : Server side control
Change all input and button into server controls (add runat=server) controls into server , then you can catch the event on server side in code behind like you are trying to do. good place to start
In server side approach, you have chance to use built in validators.
ASP.NET provides the following validation controls:
RequiredFieldValidator.
RangeValidator.
CompareValidator.
RegularExpressionValidator.
CustomValidator.
ValidationSummary.
for validator refer here
I am a new developer and I what I am trying to accomplish is hiding the radio buttons in the bottom DIV and the btnSetFinishState when clicked shows the bottom DIV (which it does from code behind). But the radio buttons when clicked do not fire the code behind method.
Here is .aspx:
<div class="row">
<asp:Button ID="btnSetFinishState" runat="server" Text="FINISHED" OnClick="btnSetFinishState_Click" UseSubmitBehavior="False" Enabled="False" />
</div>
<div class="row" id="finishedBlock" runat="server" visible="false">
<asp:Label ID="lblSetFinishText" runat="server" Text="Are you sure you want to set state to finished?" />
<div data-toggle="buttons" id="divRadioButtons">
<label id="btnFinishyes" class="btn btn-default col-sm-6 col-xs-6">
<asp:RadioButton ID="finishyes" Text="Yes" GroupName="finish" runat="server" AutoPostBack="true" OnCheckedChanged="finishyes_CheckedChanged" />
</label>
<label id="btnFinishno" class="btn btn-default col-sm-6 col-xs-6">
<asp:RadioButton ID="finishno" Text="No" GroupName="finish" runat="server" AutoPostBack="true" OnCheckedChanged="finishno_CheckedChanged" />
</label>
</div>
</div>
The aspx.cs code:
protected void btnSetFinishState_Click(object sender, EventArgs e)
{
// if neither radio button clicked
if (!finishyes.Checked && !finishno.Checked)
{
finishedBlock.Visible = true; // show the radio button DIV
//return;
}
}
protected void finishno_CheckedChanged(object sender, EventArgs e)
{
finishedBlock.Visible = false; // hide the radio buttons
finishno.Checked = false; // reset the no button to false
}
protected void finishyes_CheckedChanged(object sender, EventArgs e)
{
// set the finished state code
}
Is there e reason why btnSetFinishState is set to Enabled="False" ?
Because I tested this code and it works
aspx code
<div class="row">
<asp:Button ID="btnSetFinishState" runat="server" Text="FINISHED" OnClick="btnSetFinishState_Click" UseSubmitBehavior="False" Enabled="true" />
</div>
<div class="row" id="finishedBlock" runat="server" visible="false">
<asp:Label ID="lblSetFinishText" runat="server" Text="Are you sure you want to set state to finished?" />
<div data-toggle="buttons" id="divRadioButtons">
<label id="btnFinishyes" class="btn btn-default col-sm-6 col-xs-6">
<asp:RadioButton ID="finishyes" Text="Yes" GroupName="finish" runat="server" AutoPostBack="true" OnCheckedChanged="finishyes_CheckedChanged" />
</label>
<label id="btnFinishno" class="btn btn-default col-sm-6 col-xs-6">
<asp:RadioButton ID="finishno" Text="No" GroupName="finish" runat="server" AutoPostBack="true" OnCheckedChanged="finishno_CheckedChanged" />
</label>
</div>
</div>
aspx.cs
protected void btnSetFinishState_Click(object sender, EventArgs e)
{
// if neither radio button clicked
if (!finishyes.Checked && !finishno.Checked)
{
finishedBlock.Visible = true; // show the radio button DIV
//return;
}
}
protected void finishno_CheckedChanged(object sender, EventArgs e)
{
finishedBlock.Visible = false; // hide the radio buttons
finishno.Checked = false; // reset the no button to false
}
protected void finishyes_CheckedChanged(object sender, EventArgs e)
{
// set the finished state code
Response.Redirect("WebForm2.aspx");
}
I ran your code in my machine and found event's are firing exactly.
So , I think the different between your environment and mine may be <%# Page directive and missing AutoEventWireup="true" property.
Please share your Asp.net version and project info such as
is there any master pages or not.
UPDATE:
Please create a new sample web form application in visual studio and add a new web form say 'form1', paste your aspx and code behind to the newly added 'form1'. Test and if successfull then check the difference in aspx and code behind with your existing project.Also please let us know.