UpdatePanel triggers UpdateProgress of other usercontrol also in asp.net webform - c#

I am working on a webform which has two UpdatePanels; one inside UserControl and other inside the main page. When the pager user-control (< 1 2 3 >) of Main page is invoked it shows the corresponding UpdateProgress of 'Latest News' Section but also shows the Progress Bar of 'Subscribe' User-control.
I tried to change the properties but it keeps on coming; if I keep UpdateMode="Conditional" for user control then progress bar goes in loop and show continuously.
How can I make changes to this code to show only corresponding progress bar. I have looked over 50 example but nun seems to be matching. I would appreciate if someone can help me to get this fixed.
<!-- LatestNewArea -->
<div class="LatestNewArea">
<asp:UpdatePanel ID="updLatestNews" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Repeater ID="rptLatestNews" runat="server" EnableViewState="False" onitemdatabound="rptLatestNews_ItemDataBound">
<ItemTemplate>
<asp:HyperLink ID="hylLatestNews" CssClass="chylLatestNews" runat="server" NavigateUrl=''>
<div class="LatestNewsWrapper">
<div class="LatestNewsDateBox">
<div class="LNYYYY">
<asp:Label ID="lblYYYY" runat="server" Text="2012"></asp:Label>
</div>
<div class="LNDDMM">
<asp:Label ID="lblDDMM" runat="server" Text="12/08"></asp:Label>
</div>
</div>
<div class="LatestNewsTitle">
<asp:Label ID="lblLatestNewsTitle" runat="server" Text="First News for the Website"></asp:Label>
</div>
<div class="LatestNewsHDate">
<asp:Label ID="Label1" runat="server" Text="Hijri: 15 Rajab 1433"></asp:Label>
</div>
<div class="LatestNewsDesc">
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
</div>
</div>
<div class="LNHLine"> </div>
</asp:HyperLink>
</ItemTemplate>
</asp:Repeater>
<!-- Pager -->
<div class="LatestNewsPagerWrapper">
<div class="LatestNewsPagerInnerWrapper">
<asp:UpdateProgress ID="UpdateProgress1" runat="server" DisplayAfter="50" AssociatedUpdatePanelID="updLatestNews" >
<ProgressTemplate>
<div id="imgLoadingArticleList" class="imgLoadingArticleList">
<asp:Image ID="imgLoading" runat="server" ImageUrl="~/images/ajax-loader-bar2.gif" />
</div>
</ProgressTemplate>
</asp:UpdateProgress>
<uc1:PagerControl ID="PagerControl1" runat="server" CssClass="gold-pager" PageMode="LinkButton" />
</div>
</div>
<!-- Pager -->
</ContentTemplate>
</asp:UpdatePanel>
</div>
<!-- LatestNewArea -->
User Control Page Code
<script type="text/javascript">
function onUpdating() {
// get the divImage
var panelProg = $get('divImage');
// set it to visible
panelProg.style.display = '';
// hide label if visible
var lbl = $get('<%= this.pnlSubscribe.ClientID %>');
lbl.innerHTML = '';
}
function onUpdated() {
// get the divImage
var panelProg = $get('divImage');
// set it to invisible
panelProg.style.display = 'none';
}
</script>
<table cellpadding="0" cellspacing="0" class="SubscribeContainer">
<tr>
<td align="center">
<table cellpadding="0" cellspacing="0" class="SubscribeWrapper" border="0">
<tr>
<td valign="top">
<asp:UpdatePanel ID="updSubscribe" runat="server" >
<ContentTemplate>
<asp:Panel ID="pnlSubscribe" runat="server" Height="10px">
<div class="SubHeading"><asp:Label ID="lblTitle" runat="server" Text="JOIN US"></asp:Label></div>
<div class="dSubName">
<asp:TextBox ID="txtName" CssClass="txtSubscribe" runat="server" Text="NAME" onfocus="if(this.value=='NAME')this.value='';" onblur="if(this.value=='')this.value='NAME';"></asp:TextBox>
</div>
<div class="dSubEmail">
<asp:TextBox ID="txtEmail" CssClass="txtSubscribe" runat="server" Text="YOUR EMAIL" onfocus="if(this.value=='YOUR EMAIL')this.value='';" onblur="if(this.value=='')this.value='YOUR EMAIL';"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEmailSub" runat="server" ErrorMessage="*"
ControlToValidate="txtEmail" ValidationGroup="SubEmail" ></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revEmailSub" runat="server"
ErrorMessage="*" ControlToValidate="txtEmail" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"
ValidationGroup="SubEmail" ></asp:RegularExpressionValidator>
</div>
<div class="dSubSubmit">
<asp:Button ID="btnSubscribe" CssClass="btnSubscribe" runat="server" ValidationGroup="SubEmail" Text="Subscribe" onclick="btnSubscribe_Click" />
</div>
</asp:Panel>
<div class="dSubMSG">
<asp:Label ID="lblMSG" runat="server" Text=""></asp:Label>
</div>
<div id="divImage" style="display:none" class="dSubAni">
<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/loader-sub.png" Visible="true"/>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanelAnimationExtender ID="UpdatePanelAnimationExtender1" TargetControlID="updSubscribe" runat="server">
<Animations>
<OnUpdating>
<Parallel duration="0">
<ScriptAction Script="onUpdating();" />
<EnableAction AnimationTarget="btnSubscribe" Enabled="false" />
</Parallel>
</OnUpdating>
<OnUpdated>
<Parallel duration="0">
<ScriptAction Script="onUpdated();" />
<EnableAction AnimationTarget="btnSubscribe" Enabled="true" />
</Parallel>
</OnUpdated>
</Animations>
</asp:UpdatePanelAnimationExtender>
</td>
</tr>
</table>
</td>
</tr>
</table>

I tried many solution but non of them worked in a proper way. Finally i decided to replace UpdatePanelAnimationExtender of user control with UpdateProgress as I was able to trap the initiating UpdatePanel for AsyPostback
For some reason i was not able to trap AsyPostback when i used UpdatePanelAnimationExtender
BELOW IS A WORKING CODE
// Function to hide control on update
function onUpdateOfSubscribe() {
var panelProg = $get('divImage');
// set it to visible
panelProg.style.display = '';
// hide label if visible
var lbl = $get('<%= this.pnlSubscribe.ClientID %>');
lbl.innerHTML = '';
}
//Code to track the initiating event so to associate updateprogress
var currentPostBackElement;
function pageLoad() {
var manager = Sys.WebForms.PageRequestManager.getInstance();
manager.add_initializeRequest(OnInitializeRequest);
}
//On OnInitializeRequest
function OnInitializeRequest(sender, args) {
var manager = Sys.WebForms.PageRequestManager.getInstance();
currentPostBackElement = args.get_postBackElement().parentElement;
var cmdAuthoriseButton = '<%= btnSubscribe.ClientID %>';
if (cmdAuthoriseButton == args._postBackElement.id) {
// Show UpdateProgress for subscribe
onUpdateOfSubscribe();
}
}
</script>
<table cellpadding="0" cellspacing="0" class="SubscribeContainer">
<tr>
<td align="center">
<table cellpadding="0" cellspacing="0" class="SubscribeWrapper" border="0" >
<tr>
<td valign="top">
<asp:UpdatePanel ID="updSubscribe" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Panel ID="pnlSubscribe" runat="server" Height="10px">
<div class="SubHeading"><asp:Label ID="lblTitle" runat="server" Text="JOIN US"></asp:Label></div>
<div class="dSubName">
<asp:TextBox ID="txtName" CssClass="txtSubscribe" runat="server" Text="NAME" onfocus="if(this.value=='NAME')this.value='';" onblur="if(this.value=='')this.value='NAME';"></asp:TextBox>
</div>
<div class="dSubEmail">
<asp:TextBox ID="txtEmail" CssClass="txtSubscribe" runat="server" Text="YOUR EMAIL" onfocus="if(this.value=='YOUR EMAIL')this.value='';" onblur="if(this.value=='')this.value='YOUR EMAIL';"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEmailSub" runat="server" ErrorMessage="*"
ControlToValidate="txtEmail" ValidationGroup="SubEmail" ></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revEmailSub" runat="server"
ErrorMessage="*" ControlToValidate="txtEmail" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"
ValidationGroup="SubEmail" ></asp:RegularExpressionValidator>
</div>
<div class="dSubSubmit">
<asp:Button ID="btnSubscribe" CssClass="btnSubscribe" runat="server" ValidationGroup="SubEmail" Text="Subscribe" onclick="btnSubscribe_Click" />
</div>
</asp:Panel>
<div class="dSubMSG">
<asp:Label ID="lblMSG" runat="server" Text=""></asp:Label>
</div>
<div id="divImage" style="display:none" class="dSubAni">
<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/loader-sub.png" Visible="true"/>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubscribe" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="updSubscribe" >
<ProgressTemplate>
</ProgressTemplate>
</asp:UpdateProgress>
</td>
</tr>
</table>
</td>
</tr>
</table>

Related

why i lost filtered results after change datapager index

Look in Gif and see the problem , when i type in textbox and search the result is fine after i click for other page the search condition lost
<head runat="server">
<title></title>
<link href="App_Themes/Theme1/CSS/Usual.css" rel="stylesheet" />
<link href="Table.css" rel="stylesheet" />
<style>
body
{
font-family: Poppins !important
}
input
{
font: unset !important
}
</style>
<script>
function UpdatePanel() {
__doPostBack("<%=TextBox1.ClientID%>", '')
}
</script>
<link href="App_Themes/Theme1/CSS/Bootstrap.css" rel="stylesheet" />
and body
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div class="table-b">
<div class="row d-flex justify-content-center">
<div class="col-md-6">
<div class="tables">
<div class="table-search">
<asp:TextBox AutoCompleteType="None" ID="TextBox1" onkeyup="UpdatePanel()" AutoPostBack="false" OnTextChanged="TextBox1_TextChanged" CssClass="key" runat="server" placeholder="Search"></asp:TextBox>
<div class="line-1"></div>
<div class="line-0"></div>
</div>
<asp:UpdatePanel ID="UpdatePanel1" RenderMode="Block" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="product_id">
<ItemTemplate>
<tr style="">
<td>
<asp:Label Text='<%# Eval("product_id") %>' runat="server" ID="product_idLabel" />
</td>
<td>
<asp:Label Text='<%# Eval("product_name") %>' runat="server" ID="product_nameLabel" />
</td>
<td>
<asp:Label Text='<%# Convert.ToInt32(Eval("list_price")).ToString("N0") %>' runat="server" ID="list_priceLabel" />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server" style="width: 100%; text-align: right">
<tr runat="server" class="thead">
<th runat="server">id</th>
<th runat="server">name</th>
<th runat="server">price</th>
</tr>
<tr runat="server" id="itemPlaceholder"></tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager runat="server" ID="DataPager1">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False"></asp:NextPreviousPagerField>
<asp:NumericPagerField></asp:NumericPagerField>
<asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False"></asp:NextPreviousPagerField>
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:ProductConnectionString %>' SelectCommand="SELECT product_name, product_id, list_price FROM production.products"></asp:SqlDataSource>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="TextBox1" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
</div>
</div>
</div>
</form>
and this is code behind
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
SqlDataSource1.SelectCommand = "SELECT product_name, product_id, list_price FROM production.products where product_name like '%" + TextBox1.Text + "%'";
SqlDataSource1.DataBind();
ListView1.DataBind();
}

Prevent refresh page on list view button click in asp .net

I'm working on product cart page. Below is the code I'm working with. In the list view I'm getting all the products images as buttons. I want to update the carousel when any of the image in the list view clicked.
But When I click the image the page refreshes, I tried using update panel but since the button are dynamic can't able to find a proper way to handle it.
<div class="col-md-8 single-top-in simpleCart_shelfItem">
<div style="align-content: center">
<strong>CLICK THE IMAGE TO SELECT </strong>
</div>
<asp:ListView ID="ImagesList" runat="server"
DataKeyNames="ID"
GroupItemCount="14"
OnPagePropertiesChanging="ImagesList_PagePropertiesChanging" class="data" OnSelectedIndexChanged="OnSelectedIndexChanged">
<EmptyDataTemplate>
No Images found.
</EmptyDataTemplate>
<LayoutTemplate>
<table>
<tr runat="server" id="groupPlaceholder" />
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<td runat="server" id="itemPlaceholder" />
</tr>
</GroupTemplate>
<ItemTemplate>
<td>
<div class="data" data-image='<%#"assets/products/"+Eval("ImageUrl").ToString() %>'
data-name='<%# Eval("Description") %>' data-price='<%# Eval("Price") %>'
data-image1='<%#"assets/products/1_"+Eval("ImageUrl").ToString() %>'
data-image2='<%#"assets/products/2_"+Eval("ImageUrl").ToString() %>'>
<asp:LinkButton ID="GridBtn" runat="server" CssClass="myButton"
CommandName="Change"
OnCommand="btnDetails_Command"
CommandArgument='<%# Eval("Notes") %>'>
<img src='<%#"assets/products/"+Eval("ImageUrl").ToString() %>' class="image" style="width: 50px; height: 50px" alt="Change" /></asp:LinkButton>
</div>
</td>
</ItemTemplate>
</asp:ListView>
</div>
<div class="col-md-4 single_left pull-left left">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<div class="flexslider">
<ul class="slides">
<li id="image3" data-thumb="">
<%--<img id="image3" src="assets/products/1_ZP244.jpg" />--%>
<img id="image" src="assets/products/1_ZP244.jpg" />
<%-- <asp:Image ID="image" src="assets/products/1_ZP244.jpg" runat="server" />--%>
</li>
<li id="image4" data-thumb="">
<%--<img id="image4" src="assets/products/1_ZP244.jpg" />--%>
<img id="image1" src="assets/products/1_ZP244.jpg" />
<%--<asp:Image ID="image1" src="assets/products/1_ZP244.jpg" runat="server" />--%>
</li>
<li id="image5" data-thumb="">
<%--<img id="image5" src="assets/products/1_ZP244.jpg" />--%>
<img id="image2" src="assets/products/1_ZP244.jpg" />
<%--<asp:Image ID="image2" src="assets/products/1_ZP244.jpg" runat="server" />--%>
</li>
</ul>
</div>
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" />
</Triggers>
</asp:UpdatePanel>
</div>
<script>
$(".data").mouseover(function () {
var image = $(this).attr('data-image');
var image1 = $(this).attr('data-image1');
var image2 = $(this).attr('data-image2');
var name = $(this).attr('data-name');
var price = $(this).attr('data-price');
var btnID = $(this).attr('ID');
$(".left").find('#image').attr('src', image);
$(".left").find('#image1').attr('src', image1);
$(".left").find('#image2').attr('src', image2);
$(".left").find('#image3').attr('data-thumb', image);
$(".left").find('#image4').attr('data-thumb', image1);
$(".left").find('#image5').attr('data-thumb', image2);
$(".left").find('#name').text(name);
$(".left").find('#price').text(price);
$(".left").find('#price').text(price);
})
</script>
You can register button for async postback inside an updatepanel by add a new OnPreRender event on the button:
protected void btnReloadQty_PreRender(object sender, EventArgs e)
{
ScriptManager scriptMan = ScriptManager.GetCurrent(this.Page);
scriptMan.RegisterAsyncPostBackControl((LinkButton)sender);
}

ModalPopupExtender hides when dropdown post back works

I have a model pop up extender, within this pop up i have a dropdown list with AutopostBack="True". Now when I select one dropdown value the ModalPopupExtender hides. Let me know the reason??? Someone preferred to put update panel but still the problem exists
My pop up controls is,
<cc1:ToolkitScriptManager runat="server" ID="ToolkitScriptManager1" EnableScriptGlobalization="true"></cc1:ToolkitScriptManager>
<asp:HiddenField ID="HiddenField1" runat="server" />
<cc1:ModalPopupExtender ID="ModalPopupExtender3" runat="server"
BehaviorID="modalPopupExtender3"
TargetControlID="HiddenField1"
OkControlID="cancel1"
BackgroundCssClass="modalPopup" >
</cc1:ModalPopupExtender>
<!-- Update section-->
<div id="updatdediv1" visible="false" >
<div class="portlet box blue" id="Div3">
<div class="portlet-title">
<div class="caption"><i class="icon-reorder"></i> Add Salary Component </div>
<div class="tools">
<asp:imagebutton ID="Imagebutton2" runat="server" class="close" ImageUrl="~/jimage/clossse.PNG" />
</div>
</div>
<div class="portlet-bodypop">
<div class="controls">
<label class="control-label">Pay Grade:</label>
<asp:DropDownList ID="ddpaygrade" runat="server" AutoPostBack="true" class="m-wrap large" AppendDataBoundItems="false" ></asp:DropDownList>
</div>
<div class="controls">
<label class="control-label">DA %:</label>
<asp:TextBox ID="txtda" runat="server" class="m-wrap large" ReadOnly="true"></asp:TextBox>
</div>
<div class="controls">
<label class="control-label">Basic:</label>
<asp:TextBox ID="txtbasic" runat="server" class="m-wrap large"></asp:TextBox>
</div>
<div class="controls">
<label class="control-label">Calculated DA:</label>
<asp:TextBox ID="txtcalculatedDA" class="m-wrap large" runat="server" ></asp:TextBox>
</div>
<div class="form-actions1">
<button id="Button2"onclick="myFunction()"" style="display:none" >Save</button>
<asp:Button ID="btnedit2" runat="server" Text="Submit" CssClass="btn blue" ValidationGroup="grp1" />
<asp:Button ID="btncancel3" runat="server" Text="Cancel" CssClass="btn"/>
<asp:Label ID="label1" runat="server" Text="" Visible="false"></asp:Label>
</div>
</div>
</div>
</div>
<!-- temp panel-->
<asp:Panel ID="kj" runat="server" >
<table >
<tr><td class="style9">
<table >
<tr> <td class="style8"> </td> </tr>
<tr >
<td align="left" class="style12">
<asp:Button ID="cancel1" runat="server" Text="Cancel" Style=" display:none"
</td>
</tr>
</table>
</td></tr></table>
</asp:Panel>
If you need the modal popup extender to "survive" the postback, then you will have to manage that yourself. Handle the dropdown's SelectedIndexChanged event and show the popup there:
protected void ddpaygrade_SelectedIndexChanged(object sender, EventArgs e)
{
ModalPopupExtender3.Show();
}
Don't forget to wire-up the event in your markup:
<asp:DropDownList ID="ddpaygrade" runat="server" AutoPostBack="true"
class="m-wrap large" AppendDataBoundItems="false"
OnSelectedIndexChanged="ddpaygrade_SelectedIndexChanged" >
</asp:DropDownList>

Two Model Popup's in a Same Page

I am working in C#.Net and Ajax Concepts. I am having 2 ModelPopup Extender in a page. I am also having 2 Buttons in that page. When i click the 1st Button 1 MP should be displayed and when i click the 2nd Button, 2nd MP should get displayed. This works fine for me for the first time. [i.e] When i click the 1st Button, 1st MP is displayed and When i click the 2nd Button, 2nd MP is displayed and once again if i click the 1st Button nothing happens.
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<ajaxToolKit:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panel1" TargetControlID="Button2">
</ajaxToolKit:ModalPopupExtender>
<asp:Button ID="Button2" ToolTip="Location" runat="server" Text="Location(+)"
OnClientClick="LocClick();" />
<asp:Panel ID="Panel1" runat="server" Style="display: block; width: 600px; overflow: scroll;
height: 440px;" BackColor="White">
<table>
<tr valign="top">
<td width="650">
<ct:ASTreeView ID="astvMyTree" runat="server" BasePath="~/Scripts/astreeview/" DataTableRootNodeValue="0"
BackColor="White" EnableRoot="false" EnableNodeSelection="true" EnableCheckbox="false"
EnableDragDrop="false" EnableTreeLines="true" EnableNodeIcon="false" EnableCustomizedNodeIcon="false"
EnableDebugMode="false" EnableContextMenuAdd="false" EnableParentNodeExpand="false"
EnableAjaxOnEditDelete="false" AutoPostBack="true" OnOnSelectedNodeChanged="astvMyTree_OnSelectedNodeChanged" />
</td>
<td>
<div id="divConsole" runat="server">
</div>
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<ContentTemplate>
<ajaxToolKit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="Panel2"
TargetControlID="Button1">
</ajaxToolKit:ModalPopupExtender>
<asp:Button ID="Button1" ToolTip="Product" runat="server" Text="Product(+)"
OnClientClick="ProdClick();" />
<asp:Panel ID="Panel2" runat="server" Style="display: block; width: 600px; overflow: scroll;
height: 440px;" BackColor="White">
<table>
<tr valign="top">
<td width="650">
<ct:ASTreeView ID="ASTreeView1" runat="server" BasePath="~/Scripts/astreeview/" DataTableRootNodeValue="0"
BackColor="White" EnableRoot="false" EnableNodeSelection="true" EnableCheckbox="false"
EnableDragDrop="false" EnableTreeLines="true" EnableNodeIcon="false" EnableCustomizedNodeIcon="false"
EnableDebugMode="false" EnableContextMenuAdd="false" EnableParentNodeExpand="false"
EnableAjaxOnEditDelete="false" AutoPostBack="true" OnOnSelectedNodeChanged="astvMyTree_OnSelectedNodeChanged" />
</td>
<td>
<div id="div4" runat="server">
</div>
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
I am just changing the back color of buttons in LocClick as well as ProdClick.
<script type="text/javascript">
function LocClick() {
var location = document.getElementById("<%= Button2.ClientID %>");
location.style.background = '#72BD66';
var product = document.getElementById("<%= Button1.ClientID %>");
product.style.background = '#065581';
var lastYear = document.getElementById('<%=chkLastYear.ClientID%>');
lastYear.checked = false;
}
How to fix this...

Master page popup login control using ajaxcontroltoolkit don't work

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;
}
}

Categories