I have a webpage that is setup like so:
There is a ListView that has an item for each record in one of our SQL tables. Each of these items has a CollapsiblePanel in it that can be expanded to show more detail about the given record.
My Issue:
When I expand one panel and then wait for it to complete...everything is okay. However, if I try to expand multiple of those collapsiblepanels at once (meaning before the first panel is completely expanded)...only the last panel expands showing its data.
My Question:
Is it possible to have each of these panels expand asynchronously? Seems silly that I have to wait for one panel to extend before I can extend another.
My aspx:
I modified this aspx a little bit by removing unneeded code to make it less confusing.
<asp:UpdatePanel ID="UpdPnlBGList" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<div class="content-box">
<asp:Panel ID="pnlBGResult" runat="server">
<asp:ListView ID="lvSummary" runat="server" ItemPlaceholderID="placeholderBGList"
OnItemDataBound="lvSummary_ItemDataBound" OnItemCommand="lvSummary_ItemCommand">
<LayoutTemplate>
<table runat="server" id="tblList" cellpadding="0" cellspacing="0" border="0" style="table-layout: fixed;">
<tr id="placeholderBGList" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server">
<td>
<asp:UpdatePanel ID="UpdBgItemTemplate" runat="server" ChildrenAsTriggers="true"
UpdateMode="Conditional">
<ContentTemplate>
<div class="bgList">
<asp:Panel ID="pnlSummary" runat="server">
<table id="tblBgList" runat="server" cellpadding="0" cellspacing="0" border="0" style="border-collapse: collapse;
border-spacing: 0px;">
<tr>
<td class="imageColumn">
<asp:ImageButton ID="imgCollapsible" CssClass="first" ImageUrl="~/Images/branding/plus.gif"
runat="server" CommandName="ExpandCollapse" Style="cursor: pointer; padding-right: 5px;" />
</td>
<td width="600px">
<asp:Label ID="lblBGName" runat="server" Text='<%# Eval("BGName")%>' CssClass="bgName"></asp:Label>
<asp:Label ID="lblDatePosted" runat="server" CssClass="datePosted"></asp:Label>
</td>
<td colspan="2">
<div style="float: right;">
<asp:Label ID="lblAccountNumber" runat="server" CssClass="accountReview"></asp:Label>
<asp:Label ID="lblAccountNumberText" runat="server" CssClass="accountReview"></asp:Label>
</div>
</td>
</tr>
<tr>
<td>
</td>
<td width="600px">
<asp:Label ID="lblBillToAddress" runat="server" Text='<%# Eval("BillToAddress")%>'
CssClass="billToAddress" Style="font-weight: bold;"></asp:Label>
</td>
<td>
<div style="float: right;">
<asp:ImageButton ID="imgViewAuthLetter" ImageUrl="~/Images/branding/document.jpeg"
CssClass="first" runat="server" OnClick="imgViewAuthLetter_Click" />
<asp:LinkButton ID="lnkAuthorizationLetter" runat="server" Text="View authorization letter"
class="link_button" OnClick="lnkAuthorizationLetter_Click" OnClientClick="dirtySuppress();"
OnPreRender="addTrigger_PreRender" />
</div>
</td>
<td width="70px" style="float: right;">
<div style="float: right;">
<asp:HyperLink ID="lnkExportImage" runat="server" ImageUrl="/Images/branding/export.jpg"
CssClass="hiperlinkExport" OnClick="dirtySuppress();" />
<asp:HyperLink ID="lnkExportText" runat="server" Text="Export" CssClass="hiperlinkExport"
OnClick="dirtySuppress(); precheckURL(this.href); return false;" />
</div>
</td>
</tr>
<tr>
<td colspan="4" style="padding: 0px;">
<asp:Panel Style="margin-left: 50px;" ID="pnlDetails" runat="server">
<of:AccountNumberListControl ID="accountNumberList" runat="server"></of:AccountNumberListControl>
</asp:Panel>
<cc1:CollapsiblePanelExtender ID="cpe" runat="Server" TargetControlID="pnlDetails"
CollapsedSize="0" Collapsed="True" ExpandControlID="imgCollapsible" CollapseControlID="imgCollapsible"
AutoCollapse="False" AutoExpand="False" ScrollContents="false" ImageControlID="imgCollapsible"
ExpandedImage="~/Images/branding/minus.gif" CollapsedImage="~/Images/branding/plus.gif"
ExpandDirection="Vertical" />
</td>
</tr>
<tr>
<td>
</td>
<td colspan="3" style="padding: 0px;">
<div class="itemSeperator" id="divItemSeperator" runat="server">
</div>
</td>
</tr>
</table>
</asp:Panel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:HiddenField ID="hdfAccountNumberListControlID" runat="server" Value="" />
<asp:HiddenField ID="hdfAccountNumerID" runat="server" Value="" />
</asp:Panel>
</div>
<of:CustomerSetupExportPopInControl ID="customerSetupExportPopIn" runat="server" />
</ContentTemplate>
My codebehind:
This is the code that is executed when you expand the panel. There are several controls that is populated.
private void ExpandBillingGroup(ListViewDataItem item)
{
Label accountNumberLabel;
Label accountNumberText;
HtmlControl itemSeperator;
AccountNumberListControl accountNumberList;
// set properties for fedex account number label and text.
accountNumberLabel = (Label)item.FindControl("lblAccountNumber");
accountNumberLabel.Text = "FedEx account number: ";
accountNumberLabel.CssClass = "fedExAccountNumberLabel";
accountNumberText = (Label)item.FindControl("lblAccountNumberText");
accountNumberText.Text = lvSummary.DataKeys[item.DisplayIndex].Values["FedExAccountNumber"].ToString();
accountNumberText.CssClass = "fedExAccountNumberText";
//set the properties for Export
var lnkExportImage = (HyperLink)item.FindControl("lnkExportImage");
lnkExportImage.Visible = true;
var lnkExportText = (HyperLink)item.FindControl("lnkExportText");
lnkExportText.Visible = true;
//When expanded populate Customer Setup Export control
customerSetupExportPopIn.BillingGroupID = lvSummary.DataKeys[item.DisplayIndex].Values["BillingGroupID"].ToString();
//When expanded populate AccountNumberlistControl
accountNumberList = (AccountNumberListControl)item.FindControl("accountNumberList");
if (accountNumberList != null)
{
//since we make the AccountNumberListControl not visible on collapse we have to make it visible when we expand
accountNumberList.Visible = true;
//Set the properties
accountNumberList.BillingGroupID = lvSummary.DataKeys[item.DisplayIndex].Values["BillingGroupID"].ToString();
accountNumberList.FedExAccountNumber = lvSummary.DataKeys[item.DisplayIndex].Values["FedExAccountNumber"].ToString();
accountNumberList.BillingGroupName = ((Label)lvSummary.Items[item.DisplayIndex].FindControl("lblBGName")).Text;
accountNumberList.BillToAddress = ((Label)lvSummary.Items[item.DisplayIndex].FindControl("lblBillToAddress")).Text;
accountNumberList.FirstItemNeedsToExpand = BillingGroupIsResolved;
accountNumberList.GetListOfAccountNumbers(lvSummary.DataKeys[item.DisplayIndex].Values["BillingGroupID"].ToString(), VendorID);
}
//set the properties for itemSepeartor
itemSeperator = (HtmlControl)item.FindControl("divItemSeperator");
itemSeperator.Attributes.Add("class", "itemSeperatorExpanded");
UpdatePanel upd = (UpdatePanel)item.FindControl("UpdBgItemTemplate");
upd.Update();
}
Thanks,
Holt
EDIT: Fixed grammar and title issues
Related
Hello I have following aspx code and when the button inside ItemTemplate is cliked i need to pass the Item.BookID into code behind and I am unsure how to do it as there can be multiple items in the view. Thank you help would be much appreciated.
<asp:ListView runat="server" ID="UserDetailBooks" DefaultMode="ReadOnly" ItemType="WebApplication1.Models.Borrowed" SelectMethod="GetBorrow" DeleteMethod="ReturnBook">
<EmptyDataTemplate>
<h3>No borrowed books!</h3>
</EmptyDataTemplate>
<LayoutTemplate>
<div style="margin-left: auto; margin-right: auto; width: 50%;">
<h4>Books in possesion:</h4>
<table style="border-spacing: 2px;">
<tr id="groupPlaceholder" runat="server">
</tr>
</table>
</div>
</LayoutTemplate>
<GroupTemplate>
<tr>
<td id="itemPlaceholder" runat="server"></td>
</tr>
</GroupTemplate>
<ItemTemplate>
<td><asp:Button runat="server" Text="Return" OnClick="ReturnBook" />
<%#:Item.BookTitle %>
</td>
</ItemTemplate>
</asp:ListView>
You could pass the id in the button attributes?
<asp:Button runat="server" Text="Return" BookID="<%#:Item.BookID %>" OnClick="ReturnBook" />
<%#:Item.BookTitle %>
void ReturnBook(object sender, EventArgs e) {
Button b = sender;
string BookId = b.Attributes["BookID"];
}
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';
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();
}
}
I am using RequiredFieldValidator in my asp.net program. I have a sign out button which is used to terminate the session, but when i click on this sign out button without inserting any values in any of the text box the RequiredFieldValidator throws an error and i am not able to sign out.
I want to sign out a user without inputting any of the values in the textbox.
Please check my code in case of any problem in my code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class EntryForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{// CHEK SESSION VARIABLE AND LOAD dropdownlist1 WITH VALUES
if (!IsPostBack)
{
String DB = "";
String AccountID = "";
if (Session["login"] != null && Session["db"] != null)
{
AccountID = Session["login"].ToString();
DB = Session["db"].ToString();
Label9.Text = AccountID;
}
else
{
Response.Redirect("log.aspx");
}
HiddenField1.Value = DB.ToString();
DropDown a = new DropDown();
a.filldropdown1(this.DropDownList1, DB);
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
// LOG OUT***********////////////
Session.Abandon();
Response.Redirect("log.aspx");
}
.aspx code
<%# Page Language="C#" AutoEventWireup="true" CodeFile="EntryForm.aspx.cs" Inherits="EntryForm" %>
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit.HTMLEditor" tagprefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 330px;
}
.style2
{
text-align: center;
}
.style3
{
text-align: center;
width: 38px;
}
.style4
{
text-align: center;
width: 109%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width:90%; height: 30px;">
<tr>
<td class="style1">
<asp:Label ID="Label8" runat="server" style="text-align: left"
Text="Welcome"></asp:Label>
<asp:Label ID="Label9" runat="server" style="text-align: left"></asp:Label>
</td>
<td align="center" width="100%" style="text-align: right">
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click"
style="text-align: right">Log Out</asp:LinkButton>
</td>
</tr>
</table>
</div>
<table style="width:95%;" align="center" bgcolor="Silver">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Type : "></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
ControlToValidate="DropDownList1" ErrorMessage="*"
InitialValue="<-- Select -->">*</asp:RequiredFieldValidator>
</td>
<td>
<asp:Label ID="Label2" runat="server" Text="No. :"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Width="75px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="*">*</asp:RequiredFieldValidator>
</td>
<td>
<asp:Label ID="Label3" runat="server" Text="Year :"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Width="75px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="TextBox2" ErrorMessage="Enter Year">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox2" ErrorMessage="Enter year"
ValidationExpression="^\d{4}$">YYYY</asp:RegularExpressionValidator>
</td>
<td>
<asp:Label ID="Label4" runat="server" Text="Order Date : "></asp:Label>
<asp:TextBox ID="TextBox3" runat="server" Width="75px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ControlToValidate="TextBox3" ErrorMessage="Enter proper format">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ControlToValidate="TextBox3" ErrorMessage="Enter valid date"
ValidationExpression="^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$">dd/mm/yyyy</asp:RegularExpressionValidator>
</td>
<td>
<asp:Button ID="Button2" runat="server" Text="GO" onclick="Button2_Click" />
</td>
</tr>
</table>
<br />
<table style="width:100%;">
<tr>
<td style="text-align: center">
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
style="text-align: center" Visible="False"
onselectedindexchanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
</table>
<br />
<table style="width:100%;">
<tr>
<td style="text-align: center" width="100%">
<asp:Label ID="Label5" runat="server" Text="Label" Visible="False"
style="text-align: center"></asp:Label>
</td>
<td style="text-align: center" width="100%">
<asp:Label ID="Label6" runat="server" Text="Vs" Visible="False"></asp:Label>
</td>
<td style="text-align: center" width="100%">
<asp:Label ID="Label7" runat="server" Text="Label" Visible="False"></asp:Label>
</td>
</tr>
</table>
<br />
<table style="width:100%;" border="1">
<tr>
<td class="style3" width="100%">
</td>
<td class="style4" width="100%">
<cc1:Editor ID="Editor1" runat="server" Width="60%" AutoFocus="true"
style="text-align: right" />
</td>
<td class="style2" width="100%">
</td>
</tr>
</table>
<br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:HiddenField ID="HiddenField1" runat="server"/>
</form>
</body>
</html>
There are 2 ways you can do this
put validation group property to your controls
ValidationGroup="input"
OR
On your sign out link button, put
CausesValidation="false"
Use validation group property to group the items to be validated.
http://www.w3schools.com/ASPNET/prop_webcontrol_imagebutton_validationgroup.asp
On your Sign Out button set CausesValidation property to false
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click"
CausesValidation="False"
style="text-align: right">Log Out</asp:LinkButton>
There is a property of button CausesValidation; set it to false. Than the validations on page won't fire.
I made a pop control on the master page in asp.net 3.5
please see the following code:
Main.master aspx code:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Panel ID="Panel1" runat="server"
style="display:none; background-color:White; width:700;
border-width:2px; border-color:Black; border-style:solid;
padding:20px;">
<table width="100%" border="0" cellpadding="2" cellspacing="5">
<tr>
<td><asp:Label id="labMsg" runat="server" ForeColor="Red"EnableViewState="false" />
</td>
</tr>
<tr>
<td>
<strong>Login ID :</strong>
<asp:TextBox ID="txtLogin" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td><strong>Password :</strong>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnOk" runat="server" Text="Sign In" onclick="Login" />
<asp:Button ID="btnClose" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="defaultPanel" CssClass="Default_Panel" runat="server" Visible="true">
<ul><li><asp:LinkButton ID="lnkSignIn" class="last" runat="server" Visible="true" Text="sign in"></asp:LinkButton>
<asp:LinkButton ID="lnkSignOut" class="last" runat="server" Visible="false" Text="sign out"></asp:LinkButton>
</li>
</ul>
<!-- Login Pop Ajax Control Tool Kit -->
<ajaxToolkit:ConfirmButtonExtender ID="ConfirmButtonExtender1"
runat="server" TargetControlID="lnkSignIn"
DisplayModalPopupID="ModalPopupExtender1">
</ajaxToolkit:ConfirmButtonExtender>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
CancelControlID="btnClose" OkControlID="btnOk"
PopupControlID="Panel1"
TargetControlID="lnkSignIn">
</ajaxToolkit:ModalPopupExtender>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</form>
Main.master.cs code:
public void Login(object sender, EventArgs e)
{
// return "Login Successfull";
labMsg.Text = "Login Successfull";
}
Problem:
When login button is pressed[from Default.aspx or from any other child page] it don't hit the Login method on the master page. Help is appreciated.
I have managed to solve the problem here is the code:
Master.master:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="defaultPanel" CssClass="Default_Panel" runat="server" Visible="true">
<ul id="loginLinks">
<li><asp:LinkButton ID="lnkSignIn" class="last" runat="server" Visible="true" Text="sign in"></asp:LinkButton></li>
</ul>
<!-- Login Pop Ajax Control Tool Kit -->
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" CancelControlID="btnClose" PopupControlID="pnlSignIn" TargetControlID="lnkSignIn"></ajaxToolkit:ModalPopupExtender>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Panel ID="pnlSignIn" runat="server">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<table width="100%" border="0" cellpadding="2" cellspacing="5">
<tr>
<td style="width: 35%; padding-top: 50px;">
</td>
<td>
<asp:Label ID="labMsg" runat="server" ForeColor="Red" EnableViewState="false" />
</td>
</tr>
<tr>
<td align="right" valign="middle">
<strong>Login ID :</strong>
</td>
<td>
<asp:TextBox ID="txtLogin" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right" valign="middle">
<strong>Password :</strong>
</td>
<td>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnOk" runat="server" Text="Sign In" OnClick="btnOk_Click" />
<asp:Button ID="btnClose" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
Note: 2 update panels now, removed confirmbuttonextender.
I really don't know why the login method wasn't hitting before and how come it's working now.
Master.master.cs:
protected void btnOk_Click(object sender, EventArgs e)
{
var name = txtLogin.Text;
var pwd = txtPassword.Text;
DataSet ds = new DataSet();
string userName = name;
string pwdBeforeConversion = pwd;
//Encryption of pasword
SHA1CryptoServiceProvider x = new SHA1CryptoServiceProvider();
byte[] data = Encoding.ASCII.GetBytes(pwdBeforeConversion);
data = x.ComputeHash(data);
//pass the data to service, and get a return as dataset
try
{
somelogic here
}
catch (Exception ex3)
{
if (ex3.Message == "InvalidUsernameOrPassword")
labMsg.Text = "sorry user name and password could not be found";
else if (ex3.Message == "EmailNotVerified")
labMsg.Text = "please contact ta; email is not verified";
else if (ex3.Message == "AccountDisabled")
labMsg.Text = "please contact ta; account is not verified";
else
labMsg.Text = "sorry we encounterd a techncal issue, please try logging in again";
ModalPopupExtender1.Show();
return;
}
}