I have two asp buttons in my user control inside an update panel. But when I click them the postback is not completed (I have a java script alert set to page_load to tell me when a post back occurs, for example, it fires when the dropdownlist selection is changed). I can't figure out why the buttons are not posting back.
My usercontrol, the buttons in question are createBtn and signinBtn.
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Login.ascx.cs" Inherits="TestApp2.Views.Login" %>
<asp:UpdatePanel ID="LoginMainUpdatePanel" runat="server" UpdateMode="Conditional" OnUnload="UpdatePanel_Unload">
<ContentTemplate>
<asp:TextBox ID="infoTB" runat="server" TextMode="MultiLine" />
<div>
<div class="left-align" style="background-color:blue">
<asp:button runat="server" id="createBtn" CssClass="btn btn-default" OnClick="createBtn_Click" Text="Create" /><br/>
<asp:button runat="server" id="signinBtn" CssClass="btn btn-default" OnClick="signinBtn_Click" Text="Sign In" />
</div>
<!-- Login View -->
<div id="loginView" runat="server" class="centre-form centering text-center" style="background-color:green">
<h1>Login</h1>
<asp:Label ID="info" runat="server" Text="" />
<div class="form-group">
<label for="userIn">Username</label>
<asp:TextBox runat="server" id="userIn" CssClass="form-control" TextMode="SingleLine" />
<asp:RequiredFieldValidator runat="server" id="reqUser" controltovalidate="userIn" errormessage="Enter Username" />
</div>
<div class="form-group">
<label for="passwordIn">Password</label>
<asp:TextBox runat="server" id="passwordIn" CssClass="form-control" Text="Enter Password" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" id="reqPass" controltovalidate="passwordIn" errormessage="Enter Password" />
</div>
<asp:Button runat="server" id="loginBtn" CssClass="btn btn-default" onclick="loginBtn_Click" text="Login" />
</div>
<!-- Create Account View -->
<div id="createView" runat="server" class="centre-form centering text-center" style="background-color:green">
<h1>Create</h1>
<div class="form-horizontal">
<div class="form-group" style="background-color:yellow;">
<asp:TextBox runat="server" id="personalFName" CssClass="form-control" TextMode="SingleLine" />
<label class="control-label" for="personalFName">First Name</label>
</div>
<div class="form-group">
<asp:TextBox runat="server" id="personalLName" CssClass="form-control" TextMode="SingleLine" />
<label class="control-label" for="personalLName" >Last Name</label>
</div>
<div class="form-group">
<asp:DropDownList runat="server" id="selGender" CssClass="form-control">
<asp:ListItem Value="Male" Text="Male" />
<asp:ListItem Value="Female" Text="Female" />
<asp:ListItem Value="Other" Text="Other" />
</asp:DropDownList>
<label class="control-label" for="selGender">Gender</label>
</div>
<asp:UpdatePanel ID="dobUpdatePanel" runat="server" UpdateMode="Conditional" OnUnload="UpdatePanel_Unload">
<ContentTemplate>
<div class="form-group">
<asp:DropDownList runat="server" id="selYear" CssClass="form-control" OnSelectedIndexChanged="selYear_SelectedIndexChanged" AutoPostBack="true" />
<asp:DropDownList runat="server" id="selMonth" CssClass="form-control" OnSelectedIndexChanged="selMonth_SelectedIndexChanged" AutoPostBack="true" />
<asp:DropDownList runat="server" id="selDay" CssClass="form-control"/>
<label class="control-label" for="selDay" >Date of Birth</label>
</div>
</COntentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
The code behind is as so
public partial class Login : System.Web.UI.UserControl
{
private DateMenu dobCtrl;
protected void Page_Load(object sender, EventArgs e)
{
if (Session[Paths.USERDETAILS] != null) Response.Redirect(Paths.USERCTRL_BASE + "Profile.ascx");
else setDetails();
}
protected void loginBtn_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
String SOAPbdy = "<Username>" + userIn.Text + "</Username><Password>" + passwordIn.Text + "</Password>";
HTTPRequest req = new HTTPRequest();
String response = req.HttpSOAPRequest(SOAPbdy, "GetUser");
infoTB.Text += response;
String uIDs = (new XMLParse(response)).getElementText("UserID");
int uID = 0;
Int32.TryParse(uIDs, out uID);
if (uID > 0)
{
Session["userDetails"] = response;
info.Text = "Success";
}
else info.Text = "Login failed";
}
}
private void setDetails()
{
if (dobCtrl == null) dobCtrl = new DateMenu(selYear, selMonth, selDay);
dobCtrl.setDateDropdown();
}
protected void UpdatePanel_Unload(object sender, EventArgs e)
{
MethodInfo methodInfo = typeof(ScriptManager).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
.Where(i => i.Name.Equals("System.Web.UI.IScriptManagerInternal.RegisterUpdatePanel")).First();
methodInfo.Invoke(ScriptManager.GetCurrent(Page),
new object[] { sender as UpdatePanel });
}
protected void selYear_SelectedIndexChanged(object sender, EventArgs e)
{
dobCtrl.fillDays();
}
protected void selMonth_SelectedIndexChanged(object sender, EventArgs e)
{
dobCtrl.fillDays();
}
protected void createBtn_Click(object sender, EventArgs e)
{
loginView.Visible = false;
}
protected void signinBtn_Click(object sender, EventArgs e)
{
}
}
I believe you have to register the controls for postback using
ScriptManager.RegisterPostbackControl()
https://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.registerpostbackcontrol%28v=vs.110%29.aspx
Try setting up the triggers for the UpdatePanel like so:
<asp:UpdatePanel ID="LoginMainUpdatePanel" runat="server" UpdateMode="Conditional" OnUnload="UpdatePanel_Unload">
<ContentTemplate>
<asp:TextBox ID="infoTB" runat="server" TextMode="MultiLine" />
<div>
<div class="left-align" style="background-color:blue">
<asp:button runat="server" id="createBtn" CssClass="btn btn-default" OnClick="createBtn_Click" Text="Create" /><br/>
<asp:button runat="server" id="signinBtn" CssClass="btn btn-default" OnClick="signinBtn_Click" Text="Sign In" />
</div>
[...]
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="createBtn" />
<asp:PostBackTrigger ControlID="signinBtn" />
</Triggers>
</asp:UpdatePanel>
Try adding PostBackTriggers for the UpdatePanel.
Add 2 triggers one for each of the buttons.
<asp:UpdatePanel ID="myUpdatePanel" runat="server" UpdateMode="Conditional"ChildrenAsTriggers="false">
<ContentTemplate>
//Your Content
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="createBtn" />
<asp:PostBackTrigger ControlID="Signbtn" />
</Triggers>
</asp:UpdatePanel>
It was because of the asp form validation, no postback (async or not) was occurring because the form wasn't valid. Removing that made it all work.
Related
How can I select the record in the grid view and delete or edit this record? In Asp.Net Web Form
I want this to be done with the Bootstrap modal
I do this with Entity Framework
I have only been able to code to add
The methods I know for editing and deleting are not suitable for this project and they do not work on Bootstrap Modal
Html Code:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ProductControl.aspx.cs" Inherits="AppData.Pages.ProductControl" %>
<asp:Content ID="HeadContent" ContentPlaceHolderID="Head" runat="server">
<script src="../Scripts/jquery-3.6.0.slim.min.js"></script>
<script src="../Scripts/Site.js"></script>
</asp:Content>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div class="container">
<div class="row">
<div class="col-md-12 table-responsive" id="ProductDiv">
<div class="d-flex justify-content-between align-items-center mb-3 mt-3">
<h4>List of Products</h4>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel" runat="server">
<ContentTemplate>
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#ModalAdd">
Add Product
</button>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:GridView ID="GridView" runat="server" CssClass="table text-center table-bordered table-hover" HeaderStyle-CssClass="table-dark" AutoGenerateColumns="false" DataKeyNames="Id" OnRowCommand="GridView_RowCommand">
<Columns>
<asp:TemplateField HeaderText="" ItemStyle-Font-Size="Small">
<HeaderTemplate>Row</HeaderTemplate>
<ItemTemplate><%# Container.DataItemIndex+1 %></ItemTemplate>
<ItemStyle Wrap="False" />
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Price" HeaderText="Price" />
<asp:BoundField DataField="Type" HeaderText="Type" />
<asp:BoundField DataField="Barcode" HeaderText="Barcode" />
<asp:TemplateField HeaderText="Commands" ItemStyle-Font-Size="Small">
<ItemTemplate>
<asp:LinkButton CssClass="btn btn-warning" ID="BtnEdit" runat="server">Edit</asp:LinkButton>
<asp:LinkButton CssClass="btn btn-danger" ID="BtnDelete" runat="server" data-toggle="modal" data-target="#ModalDelete">Delete</asp:LinkButton>
<asp:LinkButton CssClass="btn btn-info" ID="BtnDetail" runat="server">Detail</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<div class="row">
<asp:Label ID="LblNotFound" runat="server" Text="No Product Found" CssClass="col-12 alert alert-danger text-center" Visible="false"></asp:Label>
</div>
</div>
<!-- Modal Add -->
<asp:UpdatePanel ID="UpdatePanelModalAdd" runat="server">
<ContentTemplate>
<div class="modal" id="ModalAdd">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Add New Record</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-6">
<p>Name:</p>
<asp:TextBox ID="Name" placeholder="Name" runat="server" CssClass="form-control"></asp:TextBox>
</div>
<div class="col-6">
<p>Price:</p>
<asp:TextBox ID="Price" placeholder="Price" runat="server" CssClass="form-control"></asp:TextBox>
</div>
</div>
<div class="row">
<div class="col-6">
<br />
<p>Type:</p>
<asp:TextBox ID="Type" placeholder="Type" runat="server" CssClass="form-control"></asp:TextBox>
</div>
<div class="col-6">
<br />
<p>Barcode:</p>
<asp:TextBox ID="Barcode" placeholder="Barcode" runat="server" CssClass="form-control"></asp:TextBox>
</div>
</div>
</div>
<div class="modal-footer">
<asp:Button ID="BtnCreate" runat="server" CssClass="btn btn-success" Text="Create" OnClick="BtnCreate_Click" />
<asp:Button ID="BtnCancel" runat="server" CssClass="btn btn-danger" Text="Cancel" data-dismiss="modal" />
</div>
</div>
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="BtnCreate" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="BtnCancel" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<!-- Modal Detail -->
<asp:UpdatePanel ID="UpdatePanelModalDetail" runat="server">
<ContentTemplate>
<div class="modal" id="ModalDetail">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Detail Record</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-6">
<p>Name:</p>
<asp:Label ID="LblName" CssClass="text-secondary" runat="server" Text=""></asp:Label>
</div>
<div class="col-6">
<p>Price:</p>
<asp:Label ID="LblPrice" CssClass="text-secondary" runat="server" Text=""></asp:Label>
</div>
</div>
<div class="row">
<div class="col-6">
<br />
<p>Type:</p>
<asp:Label ID="LblType" CssClass="text-secondary" runat="server" Text=""></asp:Label>
</div>
<div class="col-6">
<br />
<p>Barcode:</p>
<asp:Label ID="LblBarcode" CssClass="text-secondary" runat="server" Text=""></asp:Label>
</div>
</div>
</div>
<div class="modal-footer">
<asp:Button ID="Button1" runat="server" CssClass="btn btn-success" Text="Create" OnClick="BtnCreate_Click" />
<asp:Button ID="Button2" runat="server" CssClass="btn btn-danger" Text="Cancel" data-dismiss="modal" />
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<!-- Modal Delete -->
<asp:UpdatePanel ID="UpdatePanelModalDelete" runat="server">
<ContentTemplate>
<div class="modal" id="ModalDelete">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Delete Record</h4>
</div>
<div class="modal-body">
<h6 class="text-center">Are you sure you want to delete this record?</h6>
<br />
<div class="text-center">
<asp:Button ID="Delete" CssClass="btn btn-danger border-2 border-dark" runat="server" Text="Delete" CommandArgument='<%# Eval("Id") %>' CommandName="Delete" />
<button id="Cancel" class="btn btn-light border-2 border-dark" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Delete" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</asp:Content>
And Backend Code:
using AppData.Models;
using System;
using System.Collections.Generic;
using System.EnterpriseServices;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AppData.Pages
{
public partial class ProductControl : System.Web.UI.Page
{
Models.ProductDbEntities Db = new Models.ProductDbEntities();
protected void Page_Load(object sender, EventArgs e)
{
if (GridView.Rows.Count > 0)
{
LblNotFound.Visible = false;
}
else
{
GridView.DataSource = Db.TblProducts.ToList();
GridView.DataBind();
}
}
protected void BtnCreate_Click(object sender, EventArgs e)
{
TblProduct Row = new TblProduct();
Row.Name = Name.Text;
Row.Price = Price.Text;
Row.Type = Type.Text;
Row.Barcode = Convert.ToInt64(Barcode.Text);
Db.TblProducts.Add(Row);
Db.SaveChanges();
Response.Redirect("ProductControl.aspx");
}
protected void BtnCancel_Click(object sender, EventArgs e)
{
Response.Redirect("Pages/ProductControl.aspx");
}
protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
var id = e.CommandArgument;
if (e.CommandName == "Delete")
{
Int64 Id = Convert.ToInt64(id);
var Row = Db.TblProducts.FirstOrDefault(n => n.Id == Id);
Db.TblProducts.Remove(Row);
Db.SaveChanges();
Response.Redirect("DataControl.aspx");
GridView.DataSource = Db.TblProducts.ToList();
GridView.DataBind();
}
}
}
}
I understand your approach, but if you are using bootstrap modals you need to write a little bit more code.
One way to achieve this is by following the next steps:
In the Delete modal add a hidden field to hold the selected productId and an event handler for the delete button:
<div class="modal-body">
<h6 class="text-center">Are you sure you want to delete this record?</h6>
<br />
<!--add this inside delete modal -->
<input type="hidden" id="productIdToDelete" runat="server" />
<div class="text-center">
<!-- remove CommandArgument and CommandName from the Delete button. They are useless in the popup. -->
<!-- add an event handler to OnClick-->
<asp:Button ID="Delete" CssClass="btn btn-danger border-2 border-dark" runat="server" Text="Delete" OnClick="BtnDelete_Click" />
...
Create event handlers for when the modal is opened in order to propagate the productId from the current row in the grid to the modal:
<script src="../Scripts/Site.js"></script>
<script type="text/javascript">
$(document).ready(
function () {
//use a jquery selector to assign an event handler to all Delete Buttons found on the page (nottice they all start with the same prexif)
$("[id*=MainContent_GridView_BtnDelete]").click(function () {
//get the id of the product from the selected row first cell and assign it to the hidden field in the modal
$("#MainContent_productIdToDelete").val($(this).closest('tr').find('td').eq(0).html());
});
});
</script>
Finally, handle the delete event in the code behind:
protected void BtnDelete_Click(object sender, EventArgs e)
{
string idVal = Request.Form[productIdToDelete.UniqueID];
var id = Convert.ToInt64(idVal);
// implement delete logic ...
}
Use the same approach for Edit. (Look at this example.)
This is my code
<form class="subscribe">
<asp:UpdatePanel ID="updSub" runat="server">
<ContentTemplate>
<div class="col-three-forth">
<div class="form-group">
<asp:TextBox runat="server" ID="txtEmail" CssClass="form-control" placeholder="Enter your email"></asp:TextBox>
</div>
</div>
<div class="col-one-third">
<div class="form-group">
<asp:Button runat="server" ID="btnSubmit" CssClass="btn btn" Text="Subscribe Now" OnClick="btnSubmit_Click" />
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" />
<asp:AsyncPostBackTrigger ControlID="txtEmail" />
</Triggers>
</asp:UpdatePanel>
</form>
and this is my code behine
protected void btnSubmit_Click(object sender, EventArgs e)
{
Email(txtEmail.Text);
}
txtEmail.Text always returns empty string no matter what was in the textbox!
how can I make it read the text in txtEmail field?
The AsyncFileUpload works. Only issue is the file name disappears when the LinkButton to repeat the AsyncFileUpload control is pressed. Is there a way to get and store the file name? FileName does not work. Not really keen on sharing code-behind but may do so if it is necessary to solve this issue.
<asp:UpdatePanel ID="LibraryResourceUpdatePanel" runat="server">
<ContentTemplate>
<div class="field-group list-of-resource">
<asp:Repeater ID="RptRequest" runat="server" OnItemDataBound="RptRequest_ItemDataBound">
<ItemTemplate>
<div class="resource">
<div class="remove-input">
<asp:LinkButton ID="LbRemoveRequest" CssClass="ic fa fa-minus-circle" runat="server" OnClick="LbRemoveRequest_Click" CausesValidation="false"></asp:LinkButton>
<span>Remove</span>
</div>
<h2>Details of Resources
<span class="counter">
<asp:Literal ID="LitCount" runat="server"></asp:Literal>
</span>
</h2>
<ul>
<li>
<fieldset class="form-group">
<legend>Accession No.</legend>
<asp:TextBox ID="TxbAccessionNumber" CssClass="form-control" runat="server" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="TxbAccessionNumber" ErrorMessage="Email is required" ForeColor="Red" Display="Dynamic" />
</fieldset>
</li>
<li>
<fieldset class="form-group">
<legend>Details</legend>
<asp:TextBox ID="TxbDetails" runat="server" Rows="4" TextMode="MultiLine" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="TxbDetails" ErrorMessage="Details are required" ForeColor="Red" Display="Dynamic" />
</fieldset>
</li>
<li>
<fieldset class="form-group">
<legend>Image</legend>
<ajaxToolkit:AsyncFileUpload runat="server"
ID="FileUpload" OnUploadedComplete="FileUpload_UploadedComplete" ClientIDMode="AutoID" PersistFile="true"/>
<asp:RequiredFieldValidator runat="server" ControlToValidate="FileUpload" ErrorMessage="File Upload required" ForeColor="Red" Display="Dynamic" />
</fieldset>
</li>
</ul>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
<div class="add-input">
<asp:LinkButton ID="LbAddRequest" CssClass="ic fa fa-plus-circle" runat="server" OnClick="LbAddRequest_Click" CausesValidation="false" ></asp:LinkButton>
<span>Add another request</span>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="LbAddRequest" EventName="click" />
</Triggers>
</asp:UpdatePanel>
First add command name to linkbutton and remove click event:
<asp:LinkButton ID="LbAddRequest" runat="server"
CommandName="AddRequest"></asp:LinkButton>
<span>Add another request</span>
And try this ItemCommand event in code-behind to get in work:
protected void RptRequest_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "AddRequest")
{
FileUpload myFileUpload = (FileUpload)e.Item.FindControl("FileUpload");
if (myFileUpload.HasFile)
{
try
{
string filename = Path.GetFileName(myFileUpload.FileName);
myFileUpload.SaveAs(Server.MapPath("~/") + filename);
myStatusLabel.Text = "Upload Success";
}
catch (Exception ex)
{
myStatusLabel.Text = "Upload Fail" + ex.Message;
}
}
else
{
myStatusLabel.Text = "myFileUpload Has No File";
}
}
}
Read detail here : https://forums.asp.net/t/1904302.aspx?FileUpload+Inside+a+Repeater+Can+t+Find+File
I have been have problems with a postback from the button submit as after the button has finished the site think its a full refresh which gives me no chance to show any failure of login message or error,
I cant seem to pinpoint why this is happening and have looked up about the page cycle but can't put my finger on it.
Heres all my code for behind the page
protected void Page_Init(object sender, EventArgs e)
{
Session["user"] = "";
Session["domain"] = "";
Session["manager"] = "";
}
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
lblError.Text = "This was a post back.";
else
lblError.Text = "This was NOT a post back.";
}
protected void btnLogin_Click(object sender, EventArgs e)
{
//Allows the variable to be used through out the app
Session["user"] = username;
Session["domain"] = domain;
Session["manager"] = null;
if (true == authenticateUser(Session["domain"].ToString(), Session["user"].ToString(), password))
Response.Redirect(Response.ApplyAppPathModifier("Update.aspx"));
}
and front
<form id="form1" runat="server" style="Width:19%;" class="pure-form pure- form-stacked">
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:Label ID="lblName" runat="server" Text="Name"></asp:Label>
<br />
<asp:TextBox ID="txtLoginID" Width="95%" Style="display:inline-block;" runat="server"></asp:TextBox>
</div>
<br/>
<asp:Label ID="lblpwd" runat="server" Text="Password"></asp:Label>
<asp:TextBox ID="txtPassword" Width="95%" TextMode="Password" runat="server"></asp:TextBox>
<asp:Label ID="lbldmn" runat="server" Text="Domain"></asp:Label>
<asp:DropDownList ID="ddlDomain" Width="95%" runat="server">
<asp:ListItem>hdnl.it</asp:ListItem>
<asp:ListItem>yodel.net</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="lblError" runat="server" ForeColor="Red" ></asp:Label>
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btnLogin" runat="server" Text="Login" Width="95%" OnClick="btnLogin_Click"
CssClass="button-success pure-button" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server"
AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div class="overlay"></div>
<div class="modal">
<h2>Please Wait.....</h2>
<img alt="Loading..." src="/Images/loading.gif" />
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</form>
I have created my own CRM system which works perfectly locally. However, when the project has been uploaded to our web server, I'm getting some weird errors. I'm hoping the one I'm describing here is the catalyst for the others.
There is a section that shows the next lead to call with a button to click so you can amend the lead contact details. It's a basic hide/show div toggle. I have validation on the textboxes in the "amendtext" div. However, the validation is completely ignored on the button click (I'm using a validation group). Remove the hide/show on the divs and the validation works fine.
Here's the code I'm using to arrange the divs and call the click to save event. I've edited out all the styling etc:
<div>
<div id="viewtext" runat="server">
<div class="leadaddress">
<p><strong><asp:Label ID="lblName" runat="server" Text=""></asp:Label></strong></p>
<p><asp:Label ID="lblAddress" runat="server" Text=""></asp:Label><br /></p>
</div>
<div>
<p><asp:Label ID="lblLeadTel" runat="server" Text=""></asp:Label></p>
</div>
<div class="leaddetailsbut">
<p><asp:LinkButton ID="clickToAmend" runat="server" OnClick="clickToAmend_Click">Amend Address</asp:LinkButton></p>
</div>
</div>
<div id="amendtext" runat="server">
<p>
<label>Company</label>
<asp:TextBox ID="tbLeadName" runat="server" ></asp:TextBox>
<asp:CustomValidator
ID="CustomValidatorLeadName" runat="server"
ControlToValidate="tbLeadName"
OnServerValidate="CustomValidatorLeadName_ServerValidate"
ValidateEmptyText="True"
ValidationGroup="Lead">
</asp:CustomValidator>
</p>
<p>
<label class="lblwidth80">Address 1</label>
<asp:TextBox ID="tbAddress1" runat="server" ></asp:TextBox>
<asp:CustomValidator
ID="CustomValidatorLeadAddress1" runat="server"
ControlToValidate="tbAddress1"
OnServerValidate="CustomValidatorAddress1_ServerValidate"
ValidateEmptyText="True"
ValidationGroup="Lead">
</asp:CustomValidator>
</p>
<p>
<label class="lblwidth80">Address 2</label>
<asp:TextBox ID="tbAddress2" runat="server" ></asp:TextBox>
</p>
<p>
<label class="lblwidth80">City</label>
<asp:TextBox ID="tbCity" runat="server" ></asp:TextBox>
<asp:CustomValidator
ID="CustomValidatorCity" runat="server"
ControlToValidate="tbCity"
OnServerValidate="CustomValidatorCity_ServerValidate"
ValidateEmptyText="True"
ValidationGroup="Lead">
</asp:CustomValidator>
<label>Postcode</label>
<asp:TextBox ID="tbPostcode" runat="server" ></asp:TextBox>
<asp:CustomValidator
ID="CustomValidatorPostcode" runat="server"
ControlToValidate="tbPostcode"
OnServerValidate="CustomValidatorPostcode_ServerValidate"
ValidateEmptyText="True"
ValidationGroup="Lead">
</asp:CustomValidator>
</p>
<div>
<p>
<label>Telephone</label>
<asp:TextBox ID="tbTelephone" runat="server" ></asp:TextBox>
<asp:CustomValidator
ID="CustomValidatorTelephone" runat="server"
ControlToValidate="tbTelephone"
OnServerValidate="CustomValidatorTelephone_ServerValidate"
ValidateEmptyText="True"
ValidationGroup="Lead">
</asp:CustomValidator>
</p>
</div>
<div>
<asp:LinkButton ID="clickToSave" runat="server" OnClick="clickToSave_Click" ValidationGroup="Lead">Save Address</asp:LinkButton>
</div>
</div>
</div>
Code behind:
protected void Page_Load(object sender, EventArgs e)
{
viewtext.Visible = true;
amendtext.Visible = false;
}
protected void clickToAmend_Click(object sender, EventArgs e)
{
viewtext.Visible = false;
amendtext.Visible = true;
}
protected void clcikToSave_Click(object sender, EventArgs e)
{
if (this.Page.IsValid)
{
//code to save the change...
viewtext.Visible = true;
amendtext.Visible = false;
}
}
I'm now starting to pull what little hair I have left...