I have a button which has probably been implemented wrong, since it causes an error 500. The page works fine without the button and I'm not sure where the problem lies.
The .aspx:
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<div id="notify_form">
<p>Please enter a new email:</p>
<table class="ms-formtable" width="100%">
<tr>
<td><input type="text" runat="server" id="txtEmail"/></td>
</tr>
<tr>
<td class="ms-formlabel"></td>
<td>
<asp:Button runat="server" ID="btnSubmit" OnClick='SaveEmail' />
<asp:Button runat="server" ID="btnCancel" OnClientClick="window.frameElement.cancelPopUp(); return false;"/>
</td>
</tr>
</table>
</div>
</asp:Content>
The SaveEmail method does nothing at the moment.
Related
I have follow two listboxes and and a left and right button.. which are contained in a updatepanel. The only problem is when clicking on the left or right button the page refreshes which is not desired.
<asp:UpdatePanel runat="server" ID="ExportUpdatePanel">
<ContentTemplate>
<div class="exportWrapper">
<table class="exportFilter">
<tr>
<td>
<h2>
<%= ExportSelectDateLabel %></h2>
</td>
</tr>
<tr>
<td>
<label>
<%= ExportFromDateLabel %></label>
<asp:TextBox runat="server" ID="exportFilterFromDate" CssClass="exportDates"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<label>
<%= ExportToDateLabel %></label>
<asp:TextBox runat="server" ID="exportFilterToDate" CssClass="exportDates"></asp:TextBox>
</td>
</tr>
</table>
<table class="exportFilter">
<tr>
<td colspan="3">
<h2>
<%= ExportSelectColumnsLabel %></h2>
</td>
</tr>
<tr>
<td>
<label>
<%= ExportAvailableColumnLabel %></label>
</td>
<td>
</td>
<td>
<label>
<%= ExportSelectedColumnLabel %></label>
</td>
</tr>
<tr>
<td>
<asp:ListBox runat="server" ID="exportFilterAvailableColumns" SelectionMode="Multiple" CssClass="exportListBox">
</asp:ListBox>
</td>
<td class="exportButtonsTd">
<div>
<asp:LinkButton runat="server" OnClick="MoveSelectedClick"><span><img src="/images/source/arrow-right.png" alt="Move Right"/></span></asp:LinkButton>
</div>
<div class="mt_10">
<asp:LinkButton runat="server" OnClick="RemoveSelectedClick"><span><img src="/images/source/arrow-left.png" alt="Move Left"/></span></asp:LinkButton>
</div>
</td>
<td id="exportedSelectedColumn">
<asp:ListBox runat="server" ID="exportFilterSelectedColumns" SelectionMode="Multiple" CssClass="exportListBox">
</asp:ListBox>
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Any ideas ?
As per your code ExportUpdatePanel section will refresh when you click on link button inside UpdatePanel. it is not full page refresh. default update mode of update panel is always. that means:
the UpdatePanel control's content is updated on every postback that originates from anywhere on the page. This includes asynchronous postbacks from controls that are inside other UpdatePanel controls and postbacks from controls that are not inside UpdatePanel controls.
here is sample test:
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
On click event both Label1 and Label2 will update.
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToLongTimeString();
Label2.Text = DateTime.Now.ToLongTimeString();
}
but only Label2 will change because it will refresh by the update panel.
Before using update panels, please read some article on how update panels work. For example, this one: http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-updatepanel-triggers
Add UpdateMode="Conditional" and ChildrenAsTriggers="true" attributes to your update panel, and it should work as you want.
<asp:UpdatePanel runat="server"
ID="ExportUpdatePanel"
UpdateMode="Conditional"
ChildrenAsTriggers="true">
I have two different buttons viz save and update. I want to open single pop-up window for both buttons, then how can I do so.? More over if pop-up is open on save buttons click then when ever it is closed, it should directed to OnClick_save() button event and if it is open from update buttons, on pop-up colse, it should directed to OnClick_Update() buttons click event.
How can I do so??
This is my code
<tr>
<td>
<table id="tblButton" runat="server">
<tr>
<td>
<asp:Button ID="btnAdd" runat="server" Text="Add" Visible="false" />
<asp:Button ID="btnUpdate" runat="server" Text="Update" Visible="false" /> <asp:Button ID="btnDelete" runat="server" Text="Delete" Visible="false" />
<asp:Button ID="btnTargetButton" runat="server" Text="PopUpTarget" Visible="false" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<cc1:ModalPopupExtender ID="ModalPopupExtenderSave" runat="server" TargetControlID="btnTargetButton" PopupControlID="passwordPopUp" DropShadow="true" PopupDragHandleControlID="header" BackgroundCssClass="modalBackground" BehaviorID="ModalPopupExtenderSave" />
</table>
<asp:Panel ID="passwordPopUp" runat="server" Style="display: none; padding: 10px;
border: 1px; border-style: solid;" BackColor="#91C83B" Width="300px" HorizontalAlign="Center"
BorderStyle="Solid" BorderWidth="5px">
<table class="TABLE100">
<tr>
<td colspan="3">
<h3 style="text-align: center;" id="header">
Confirm Password</h3>
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
<tr>
<td>
</td>
<td width="50px">
<asp:Label ID="lblPasswrd" runat="server" Text="Password" Font-Bold="True" Font-Size="Larger"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtPassword" runat="server" SkinID="TextBoxLong"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="SUBMIT" Width="70px" OnClick="btnSubmit_Click"/>
</td>
</tr>
</table>
</asp:Panel>
Some how I have solved the problem up to certain extent.
Now the problem is three different buttons viz. Insert, Update and delete buttons are responsible for opening pop-up window which in turn opens an ASP:panel the panel contains submit button. So on submit button, can I know which button was responsible for opening a panel.???
You can use a hidden button as modal popup's Okbutton and call then button OnClick from code. from both Save and Updated buttons.
add server side event handlers for each button click. use jquery to show popup for each button, that would be $('#button1').click and $('#button2').click from jquery.
When the form is displayed, I'd like to set focus to the CurrentPassword textbox. What is the easiest way to do this? Is there a way to access it directly using its ID? Apparently, because it is nested, referencing the control by its ID results in an unrecognized variable. Alternatively, I could write an ugly FindControl statement (some like) like this:
ChangePassword1.Controls(1).Controls(0).Controls(0).Controls(0).Controls...etc...FindControl("CurrentPassword")
but, besides being ugly, this seems brittle to GUI changes.
I could also write a recursive FindControl statement, but while it is convenient, it is less efficient than a more direct reference.
Suggestions, Ol' Wise Community?
<%# Page Title="" Language="VB" MasterPageFile="~/Master Pages/MasterPage.master" AutoEventWireup="false" CodeFile="ChangePassword.aspx.vb" Inherits="ChangePassword" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" runat="server" ContentPlaceHolderID="phPageContent">
<h1 style="text-align: left;">
Change Password
</h1>
<hr />
<asp:ChangePassword ID="ChangePassword1" runat="server">
<ChangePasswordTemplate>
<table cellpadding="1" cellspacing="0" style="border-collapse: collapse;">
<tr>
<td>
<table cellpadding="2">
<tr>
<td align="right">
<asp:Label ID="CurrentPasswordLabel" runat="server" AssociatedControlID="CurrentPassword" CssClass="CaptionLabel">Current Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="CurrentPassword" runat="server" CssClass="DefaultTextBox" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="CurrentPasswordRequired" runat="server" ControlToValidate="CurrentPassword" ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="ChangePassword1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="NewPasswordLabel" runat="server" AssociatedControlID="NewPassword" CssClass="CaptionLabel">New Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="NewPassword" runat="server" CssClass="DefaultTextBox" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewPasswordRequired" runat="server" ControlToValidate="NewPassword" ErrorMessage="New Password is required." ToolTip="New Password is required." ValidationGroup="ChangePassword1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="ConfirmNewPasswordLabel" runat="server" AssociatedControlID="ConfirmNewPassword" CssClass="CaptionLabel">Confirm New Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="ConfirmNewPassword" runat="server" CssClass="DefaultTextBox" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="ConfirmNewPasswordRequired" runat="server" ControlToValidate="ConfirmNewPassword" ErrorMessage="Confirm New Password is required." ToolTip="Confirm New Password is required." ValidationGroup="ChangePassword1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:CompareValidator ID="NewPasswordCompare" runat="server" ControlToCompare="NewPassword" ControlToValidate="ConfirmNewPassword" Display="Dynamic" ErrorMessage="The Confirm New Password must match the New Password entry." ValidationGroup="ChangePassword1"></asp:CompareValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color: Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="right">
<asp:Button ID="ChangePasswordPushButton" runat="server" CommandName="ChangePassword" Text="Submit" ValidationGroup="ChangePassword1" />
</td>
<td>
<asp:Button ID="CancelPushButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</ChangePasswordTemplate>
<MailDefinition BodyFileName="~/EmailTemplates/ChangePassword.htm" From="info-noreply#pandavisa.com" IsBodyHtml="True" Subject="Your password has changed">
</MailDefinition>
</asp:ChangePassword>
</asp:Content>
Based on the reply below, I changed the ClientIdMode of the CurrentPassword Textbox to "Static." I then added the following shown after the pre-existing first line:
<asp:Content ID="Content2" runat="server" ContentPlaceHolderID="phPageContent">
<script type="text/javascript">
$().ready(function () {
//$('.DefaultTextBox:eq(0)').focus();
$('#CurrentPassword').focus();
});
</script>
But I got the following error, same error when I uncommented the first suggestion.
Microsoft JScript runtime error: Object expected
You open for some jQuery?
$().ready(function(){
$('.DefaultTextBox:eq(0)').focus();
});
This is an old question, but I'm posting the C# way of referencing the correct textboxes in case anybody looks at this.
TextBox txtCurrentPassword = (TextBox)changepasswordCtl.ChangePasswordTemplateContainer.FindControl("CurrentPassword");
TextBox txtNewPassword = (TextBox)changepasswordCtl.ChangePasswordTemplateContainer.FindControl("NewPassword");
TextBox txtConfirmNewPassword = (TextBox)changepasswordCtl.ChangePasswordTemplateContainer.FindControl("ConfirmNewPassword");
I am using ajax model popup extender in my asp.net page. From my page , on click of Save button , i popup panel using model popup extender.
If i cause postback from model popup , my backend (asp.net) form controls are coming front (ie) in the panel.
Here is my code snippet,
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="up_Save" runat="server">
<ContentTemplate>
<div>
<table border="0" cellpadding="2" cellspacing="2" width="100%">
<tr>
<td align="center" colspan="4">
<asp:Button ID="btn_Save" runat="server" Text="Save" Width="15%" OnClick="btn_Save_Click" />
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<cc1:ModalPopupExtender ID="BarrierRelayPopup" runat="server" PopupControlID="PopUp_Panel" TargetControlID="hiddenfield" CancelControlID="btn_Cancel_PopUp">
</cc1:ModalPopupExtender>
<asp:HiddenField ID="hiddenfield" runat="server" />
<asp:Panel runat="server" ID="PopUp_Panel" Width="50%" Height="30%" BackColor="Gainsboro" BorderStyle="Groove" >
<asp:UpdatePanel runat="server" ID="PopUp">
<ContentTemplate>
<table>
<tr>
<td align="left">
<asp:Label ID="lbl_Heading" runat="server" Text="Select Relay and Barrier :"></asp:Label>
</td>
</tr>
<tr>
<td>
<B_R:Barrier_Relay ID="Barrier_Relay" runat="server"/>
</td>
</tr>
<tr>
<td align="center">
<asp:Button ID="btn_OK" runat="server" Width="60px" Text="OK" OnClick="btn_OK_Click" /> <asp:Button ID="btn_Cancel_PopUp" runat="server" Width="60px" Text="Cancel" OnClick="btn_Cancel_PopUp_Click"/>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</form>
Can anybody help me in this.
If I understand you right I think what you want to do is wrap the controls inside the modal in an updatepanel. This will prevent the modal from closing if you need to do a postback from within the popup.
I'm having a heck of a time trying to get a gridview to refresh its data after a modalpopup adds a new record to the database. Ive tried the following with no luck.
<cc2:ModalPopupExtender ID="mdlPopup" runat="server" OnOkScript="__doPostBack('<%= gvRecommendations.ClientID %>', '');" BackgroundCssClass="modalBackground"
TargetControlID="lbtnRecommendationsAddNew" PopupControlID="pnlAddNewRecommendation">
</cc2:ModalPopupExtender>
<asp:Panel ID="pnlAddNewRecommendation" runat="server" CssClass="confirm-dialog" style="display:none;" Width="500px">
<div class="inner">
<h2>New Suppressed Recomendation</h2>
<div class="base">
<table width="100%" cellpadding="5" cellspacing="0">
<tr>
<td align=left>
<asp:DropDownList ID="ddlRecomendations" runat="server" />
</td>
</tr>
<tr>
<td align="left">
<asp:Button ID="btnAddRecommendation" OnClick="btnAddRecommendation_Click" runat="server" Text="Submit" />
|
<asp:LinkButton ID="btnCancel" runat="server" Text="Cancel" ForeColor="Blue" />
<asp:LinkButton id="lbtnTopLeft" runat="server" CssClass="close" />
</div>
</td>
</tr>
</table>
</div>
</div>
</asp:Panel>
Ive also tried adding this with no luck after adding the record to the DB:
this.gvSupressedRecommendations.DataBind();
this.UpdatePanel1.Update();
I know im close but can't seem to get this to refresh.
Try reassigning your datasource before you rebind. This should work. I.e.
gvSupressedRecommendations.DataSource = <...>;
gvSupressedRecommendations.DataBind();