I am trying to create a form as part of a website. In the form the user is shown a dropdownlist with serveral options. If the user chooses the "Other" option, then they should be presented with a text box to fill the description of the "other" choice.
My idea was to hide the div that contains the text box and enable it when the user changes the dropdown list choice to "other".
I am having an issue where in asp.net the dropdownlist "selectedindexchanged" event is not being triggered. Below is the HTML code and the cs code.
<%# Page Title="" Language="C#" MasterPageFile="~/master/Site1.Master" AutoEventWireup="true" CodeBehind="form.aspx.cs" Inherits="Project.forms.form" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="menu" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Banner" runat="server">
<img src="../../image.jpg" class="img-responsive" alt="Responsive image" />
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<h2 class="branding_orange">Form</h2>
<div class="alert alert-danger" name="warningDiv" style="margin-top:10px" id="warningDiv" role="alert" runat="server">
<p name="warningMsg" id="warningMsg" runat="server"></p>
</div>
<form id="compliantForm" role="form" class="form" runat="server" data-toggle="validator" onsubmit="return validation();">
<div class="row">
.
.
.
<div class="col-xs-12 col-sm-6 col-md-4">
<div class="form-group">
<label for="person-submitting-select">Is the person submitting this complaint an: <b style="color:red">*</b></label>
<asp:DropDownList ID="cboPersonSubmitting" runat="server" AutoPostBack = "True" OnSelectedIndexChanged = "OnSelectedIndexChanged">
<asp:ListItem Text="select" Value="0" />
<asp:ListItem Text="Employee" Value="1" />
<asp:ListItem Text="Customer" Value="2" />
<asp:ListItem Text="Other" Value="3" />
</asp:DropDownList>
</div>
</div>
.
.
.
.
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="ContentPlaceHolder3" runat="server">
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Project.forms
{
public partial class form : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
cboPersonSubmitting.AutoPostBack = true;
warningDiv.Visible = false;
warningMsg.InnerHtml = "";
}
.
.
.
protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
if (cboPersonSubmitting.SelectedIndex == 3)
{
whoSubmittingDiv.Visible = true;
}
else
{
whoSubmittingDiv.Visible = false;
}
}
}
}
Based on my test, you can try the following code to show textbox when you choose Other in the dropdownlist.
Html:
<form id="form1" runat="server">
<div class="col-xs-12 col-sm-6 col-md-4">
<div class="form-group">
<label for="person-submitting-select">Is the person submitting this complaint an: <b style="color:red">*</b></label>
<asp:DropDownList ID="cboPersonSubmitting" runat="server" AutoPostBack = "True" OnSelectedIndexChanged="cboPersonSubmitting_SelectedIndexChanged">
<asp:ListItem Text="select" Value="0" />
<asp:ListItem Text="Employee" Value="1" />
<asp:ListItem Text="Customer" Value="2" />
<asp:ListItem Text="Other" Value="3" />
</asp:DropDownList>
<div class="Submitdiv" id="thediv" runat="server" visible="false">
<asp:TextBox ID="txtInput" runat="server" ></asp:TextBox>
</div>
</div>
</div>
</form>
C# code:
protected void cboPersonSubmitting_SelectedIndexChanged(object sender, EventArgs e)
{
if (cboPersonSubmitting.SelectedIndex == 3)
{
thediv.Visible = true;
}
else
{
thediv.Visible = false;
}
}
Result:
Related
When using UpdatePanel, the AsyncPostBackTrigger is not firing on the server side. Originally, I thought it was because I'm using a MasterPage and the ScriptManager was not loading correctly so I created a test template but it still won't fire. However, the UpdateProgress does appear. This button is being used to export a report from Crystal Reports. Below is my following code:
Client Side:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="WebApplication1.Test" %>
<%# Register Assembly="CrystalDecisions.Web, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<script src="cr/crystalreportviewers13/js/crviewer/crv.js" type="text/javascript">
</script>
<script>
</script>
<form id="form1" runat="server">
<div>
<p>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
</p>
</div>
<div>
<asp:Label ID="test" runat="server"></asp:Label>
<asp:RadioButtonList ID="rblFormat" runat="server" RepeatDirection="Horizontal" Width="130px" >
<asp:ListItem Text=" Excel" Value="Excel" />
<asp:ListItem Text=" PDF" Value="PDF" />
</asp:RadioButtonList>
<asp:ScriptManager runat="server" ></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Button ID="btnExport" CssClass="btn btn-primary" Text="Export" runat="server" CausesValidation="false"
OnClick="btnExport_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnExport" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div>
<font color="red"> Generating Download</font>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</div>
</form>
</body>
</html>
Server-Side
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;
using static System.Net.Mime.MediaTypeNames;
namespace WebApplication1
{
public partial class Test : System.Web.UI.Page
{
ReportDocument crystalReport;
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(this.CrystalReportViewer1);
scriptManager.RegisterPostBackControl(this.btnExport);
crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("cr/missing_dob.rpt"));
crystalReport.SetDatabaseLogon("test", "test");
CrystalReportViewer1.ToolPanelView = ToolPanelViewType.None;
CrystalReportViewer1.ReportSource = crystalReport;
}
protected void btnExport_Click(object sender, EventArgs e)
{
ExportFormatType formatType = ExportFormatType.NoFormat;
switch (rblFormat.SelectedItem.Value)
{
case "PDF":
formatType = ExportFormatType.PortableDocFormat;
break;
case "Excel":
formatType = ExportFormatType.Excel;
break;
}
crystalReport.ExportToHttpResponse(formatType, Response, true, "Report");
}
}
}
PostBackTrigger works but the UpdateProcess does not appear. I can't seem to get both working. I appreciate any help!
aspx page layout is as below
<asp:Content ID="PageContent" ContentPlaceHolderID="PageContent" runat="Server">
<div id="checkout_onePage" class="mainContentWrapper opcOverlayWrapper">
<script language="javascript" type="text/javascript">
Page_ClientValidate();
</script>
<div id="PageOverlay" runat="server" visible="false" class="opcOverlay"></div>
<ajax:Accordion ID="UserAccordion" runat="server" SelectedIndex="0" HeaderCssClass="accordionHeader"
HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent" FadeTransitions="true" SuppressHeaderPostbacks="true" TransitionDuration="250" FramesPerSecond="40" RequireOpenedPane="true" AutoSize="None">
<Panes>
<ajax:AccordionPane ID="BillingInformation" runat="server">
<Header>
<div id="billingAddr" class="widget billingAddressWidget aboveOpcOverlay">
<div class="header">
<h2>Billing Information</h2>
</div>
</div>
</Header>
<Content>
<div class="aboveOpcOverlay">
<asp:UpdatePanel ID="UPBilling" runat="server">
<ContentTemplate>
<div class="content floatleft">
<asp:PlaceHolder ID="LoginPanel" runat="server" EnableViewState="False" Visible="false">
<p class="LoginMessage">
If you have previously created an account, you can
<asp:HyperLink ID="LoginLink" runat="server" Text="log in" EnableViewState="false" CssClass="button"></asp:HyperLink>
to retrieve your saved addresses.
</p>
</asp:PlaceHolder>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</Content>
</ajax:AccordionPane>
<ajax:AccordionPane ID="ShippingInformation" runat="server">
<Header>
<div class="widget shippingAddressWidget aboveOpcOverlay">
<div class="header">
<h2>Shipping Information</h2>
</div>
</div>
</Header>
<Content>
<asp:Panel ID="ShippingAddressPanel" runat="server" Visible="true">
<div class="aboveOpcOverlay">
<div class="content" runat="server" id="Div_Main_Shipping_Information">
</div>
</div>
<table>
<tr id="trShippingAddress" runat="server" visible="false">
<td>
<uc2:AddressDetails ID="ShippingAddress" runat="server" ValidationGroupName="Shipping" />
</td>
</tr>
</table>
</asp:Panel>
</Content>
</ajax:AccordionPane>
</Panes>
</ajax:Accordion>
I have one usercontrol assigned in above page from there I am not able to find my div control named as Div_Main_Shipping_Information
My usercontrol code is as Below
Content PageContent = (Content)this.Parent.FindControl("PageContent");
Accordion UserAccordion = (Accordion)PageContent.FindControl("UserAccordion");
AccordionPane shipInfoPane = UserAccordion.Panes["ShippingInformation"];
Panel ShippingAddressPanel = (Panel)shipInfoPane.FindControl("ShippingAddressPanel");
System.Web.UI.HtmlControls.HtmlGenericControl Div_Main_Shipping_Information = (System.Web.UI.HtmlControls.HtmlGenericControl)ShippingAddressPanel.FindControl("Div_Main_Shipping_Information");
But I am not able to find my control Accordion control, panel control or my div control.
using AjaxControlToolkit;
Accordion userAccordion = (Accordion)this.Page.FindControl("UserAccordion");
AccordionPane shipInfoPane = userAccordion.Panes["ShippingInformation"];
Panel ShippingAddressPanel = (Panel)shipInfoPane.FindControl("ShippingAddressPanel");
System.Web.UI.HtmlControls.HtmlGenericControl Div_Main_Shipping_Information = (System.Web.UI.HtmlControls.HtmlGenericControl)ShippingAddressPanel.FindControl("Div_Main_Shipping_Information");
I am having an issue with my "save" linkbutton firing and am at a loss. I have included the code for the form and code-behind. I have added some testing to see if the event is firing and it doesn't appear to be so. Any help is appreciated. I am a novice coder so excuse me if there are obvious issues or a better way to proceed. Ultimate goal is to update the entry in the database for the given screen info and then redisplay to updated info.
Again thank you in advance.
UPDATE: I have included the FULL-ish CODE: (removed the sensitive info)
CODEBEHIND:
using System;
using System.Configuration;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class matter : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
...
}
protected void fvdoc_ItemCommand(object sender, FormViewCommandEventArgs e)
{
if (e.CommandName == "Update")
{
throw new Exception("Clicked");
}
throw new Exception("i've been Clicked");
}
}
PAGE:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="matter.aspx.cs" Inherits="matter" %>
<!DOCTYPE html>
<html>
<head>
<title>Wasatch Client Matter Index</title>
<link rel="shortcut icon" href="~/favicon.ico" type="image/x-icon" />
<meta name="viewport" charset="utf-8" content="width=device-width, initial-scale=1, user-scalable=no"/>
<!-- Latest compiled and minified CSS -->
<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Ubuntu+Condensed' type='text/css' />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous" />
<link rel="stylesheet" href="Content/themes/Site.css" />
<!-- Latest compiled JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"/>
</head>
<body>
<div class="navbar">
<div class="row">
<h1 class="col-lg-8 col-lg-offset-2 text-center " style="align-content:center;">Matter Index </h1>
</div>
</div>
<div class="container-fluid">
<form id="form1" runat="server">
<div class="row">
<div class="col-lg-10 col-lg-offset-1 form-group">
<asp:FormView ID="fvdoc" runat="server" DataSourceID="gvdb" OnItemCommand="fvdoc_ItemCommand">
<ItemTemplate>
<h2 class="col-md-12"><asp:Label ID="tbname" runat="server" Text=<%# Bind("docid") %> /> - <asp:Label ID="lbID" runat="server" Text=<%# Bind("sName") %> /></h2>
<div class="left col-md-10">
<legend>Matter Info:</legend>
<div class="form-group"><asp:Label runat="server" Text="Matter" AssociatedControlID="dcname"/>
<asp:TextBox ID="dcname" runat="server" CssClass="form-control" Text=<%# DataBinder.Eval(Container.DataItem,"sDocname") %> Enabled="true"/></div>
</div>
<div class="left col-md-10">
<hr />
<div class="form-group"><asp:Label runat="server" Text="Notes/Comments" AssociatedControlID="dcnotes" />
<asp:TextBox ID="dcnotes" runat="server" Rows="3" TextMode="MultiLine" Text=<%# Bind("sdocdesc") %> Enabled="true"/></div>
</div>
<div class="left col-md-6 col-md-offset-5 txsmall">
<asp:Label runat="server" Text="Filed: " Font-Bold="true" /><asp:Label ID="lblfiledate" runat="server" Text=<%# Bind("dtFiledate") %> CssClass="txsmall" Font-Italic="true" />
<asp:Label runat="server" Text="Modified: " Font-Bold="true" /><asp:Label ID="lblmodify" runat="server" Text=<%# Bind("dtLastModified") + " - " + Bind("susermodified") %> CssClass="txsmall" Font-Italic="true"/>
<asp:Label runat="server" CssClass="txsmall" id="lbltest"/>
</div>
<div class="clear-fix col-md-12">
<div class="form-group">
<asp:LinkButton runat="server" Text="Save" ID="SaveButton" CommandName="Update" CssClass="clear-fix btn btn-primary" />
<asp:LinkButton runat="server" Text="Move" ID="MoveButton" CssClass="clear-fix btn btn-primary" CausesValidation="False" href="m.aspx" />
<asp:LinkButton runat="server" Text="Home" ID="HomeButton" CssClass="clear-fix btn btn-primary" CausesValidation="False" href="default.aspx"/>
</div>
</div>
</ItemTemplate>
</asp:FormView>
</div>
</div>
<hr class="col-lg-10 col-lg-offset-1" />
</form>
</div>
...
</body>
</html>
Your link button is present inside a formview item template as can be seen below and thus you will not get the individual control event (onclick event of linkbutton). Rather you need to handle the FormView.ItemCommand and do your processing like
<asp:FormView ID="fvdoc" runat="server"
DataSourceID="gvdb" onitemcommand="itemCommandClick">
<ItemTemplate>
.......
<asp:LinkButton runat="server" Text="Save" ID="SaveButton" CommandName="Update" .........
In code behind handle this like
void itemCommandClick(Object sender, FormViewCommandEventArgs e)
{
if (e.CommandName == "Update")
{
LinkButton button = e.CommandSource as LinkButton;
//Do rest of the processing
}
}
Your FormView is missing the EditItemTemplate, like so:
<asp:FormView ID="fvdoc" runat="server" DataSourceID="gvdb" OnItemCommand="fvdoc_ItemCommand">
<ItemTemplate>
<!--... Use readonly controls like Label etc...-->
<asp:LinkButton runat="server" Text="Save" ID="EditButton" CommandName="Edit" CssClass="clear-fix btn btn-primary" />
</ItemTemplate>
<EditItemTemplate>
<!--... Use editable controls like TextBox etc...-->
<asp:LinkButton runat="server" Text="Save" ID="SaveButton" CommandName="Update" CssClass="clear-fix btn btn-primary" />
</EditItemTemplate>
</asp:FormView>
For the click on the Edit Button, change to Edit mode, then Handle the Save button to save the new values.
See the MSDN docs for more information.
I have a very simple asp.net webform page with a listview, I can not make the listView refresh on postback, only if I make a new request. I guess the listView gets its content from the viewstate or something. I databind in the Page_Load event, and i have also tried the Page_Init event. No difference.
I have probably been through the first 50 Google search results, and nothing seems to work.
How do i force the listview to refresh on postback?
Default.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="RSS_Reader.Default" %>
<%# Import namespace="RSS_Reader.Extensions" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>RSS Reader</title>
<link rel="shortcut icon" href="favicon.ico" />
<link href="css/main.css" rel="stylesheet" />
<script src="js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="js/App.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="horizontal-menu">
<ul id="horizontal-menu-list">
<li id="add-feed">Add Feed
<ul>
<li>
<input type="text" placeholder="Feed URL" /><button class="button green">Add</button>
</li>
</ul>
</li>
<li>Add Group</li>
<li>Settings</li>
</ul>
<div id="global-search">
<input type="text" id="search" placeholder="Search" />
</div>
<div style="clear: both"></div>
</div>
<div id="feeds">
<div id="feed-filter">
<asp:TextBox ID="feedUrl" runat="server" placeholder="Feed URL"></asp:TextBox>
<asp:Button ID="ThisIsAUniqueNameForAButton" runat="server" CssClass="button green" Text="Subscribe" OnClick="subscribeToFeed" />
</div>
<div id="feed-wrapper">
<asp:ListView ID="FeedCollection" runat="server">
<ItemTemplate>
<div><div class="feed-collection-icon"></div><asp:Label runat="server" ID="listFeedTitle" Text='<%# Bind("Title") %>'></asp:Label></div>
</ItemTemplate>
</asp:ListView>
</div>
</div>
<div id="content">
<div id="feed-title">Version2 - IT For Professionelle</div>
<div id="nodes">
<asp:GridView ID="nodesGridview" OnSorting="nodesGridview_Sorting" runat="server" OnSortCommand="SortGrid" AllowSorting="True" AutoGenerateColumns="false">
<EmptyDataTemplate>
No feed.
</EmptyDataTemplate>
<Columns>
<asp:TemplateField HeaderText="Title" SortExpression="title">
<ItemTemplate>
<div class="node-icon"></div> <%# XPath("title") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description" SortExpression="description">
<ItemTemplate>
<%# XPath("description").ToString().Truncate(50) %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date" SortExpression="pubDate">
<ItemTemplate>
<%# XPath("pubDate").ToString().toDate() %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<div id="reading-pane">
<asp:Label ID="readingPaneTitle" runat="server" Text="Label"></asp:Label>
</div>
</div>
<div id="footer">
Copyright © 2014 - Mads O. Nielsen
</div>
</div>
</form>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Diagnostics;
using System.Data.Entity;
using System.Data;
using System.IO;
using RSS_Reader.FeedCollection;
using RSS_Reader.FeedItem;
namespace RSS_Reader
{
public partial class Default : System.Web.UI.Page
{
private XmlDataSource feedItems;
private FeedReader feedReader;
protected void Page_Init(object sender, EventArgs e)
{
Debug.WriteLine("Page_Init");
if (!IsPostBack)
{
}
}
protected void Page_Load(object sender, EventArgs e)
{
RSS_Reader.Model db = new RSS_Reader.Model();
//var feedQuery = from emp in db.Feeds select emp;
//List<Feeds> empList = feedQuery.ToList();
FeedCollection.DataSource = db.Feeds.ToList();
feedReader = new FeedReader();
feedReader.load("http://www.version2.dk/it-nyheder/rss");
feedItems = new XmlDataSource();
feedItems.EnableCaching = false;
feedItems.ID = "feedItems";
feedItems.Data = feedReader.feed.OuterXml;
feedItems.XPath = "rss/channel/item";
nodesGridview.Width = new Unit(100.00, UnitType.Percentage);
nodesGridview.DataSource = feedItems;
FeedCollection.DataBind();
nodesGridview.DataBind();
}
protected void subscribeToFeed(object sender, EventArgs e)
{
FeedManager feedManager = new FeedManager();
feedManager.subscribe(feedUrl.Text);
}
protected void nodesGridview_Sorting(object sender, GridViewSortEventArgs e)
{
Debug.WriteLine("Sorting");
}
}
}
if it cant refresh the ListView because of save it into ViewState you can set EnableViewState property to False then server refresh it in all postback
Here's my situation. I have a web forms page, and it's getting annoying when the entire page scrolls to the top every time you click a control, so I'm trying to apply update panels to my page.
The submit button may or may not be click-able depending on whether or not the contents of individual update panels are in a proper state.
When the submit button is clicked, It can potentially affect any of the controls on the page.
I understand that I can do some of this with the <triggers> tag element of the update panel, but I don't want to have to put everything on the page into an update panel with it's own trigger, I'd rather that the submit button just reload the entire page.
For the sake of simplicity I've put together a sample project to represent my page. It has a "reset" button, to represent the "submit" button.
The Master page:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="WebApplication1.SiteMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form runat="server">
<asp:ScriptManager ID="ScriptManager" runat="server" EnablePartialRendering="true" />
<div class="page">
<div class="header">
<div class="title">
<h1>
My ASP.NET Application
</h1>
</div>
<div class="loginDisplay">
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
<AnonymousTemplate>
[ Log In ]
</AnonymousTemplate>
<LoggedInTemplate>
Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
[ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
</LoggedInTemplate>
</asp:LoginView>
</div>
<div class="clear hideSkiplink">
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
<asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
</Items>
</asp:Menu>
</div>
</div>
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</div>
<div class="clear">
</div>
</div>
<div class="footer">
</div>
</form>
</body>
</html>
The default page:
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Label runat=server Text="This lable represents things not in update panels" ID="label1"></asp:Label>
<asp:UpdatePanel ID="UpdatePanel1" runat=server>
<ContentTemplate>
<table>
<tr>
<td><asp:Button ID="button1" runat="server" OnClick="Button1_click" Text="Button 1" /></td>
<td><asp:TextBox ID="textBox1" runat="server" Text="StartText" Enabled="false" /></td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat=server>
<ContentTemplate>
<table>
<tr>
<td><asp:Button ID="button2" runat="server" OnClick="Button2_click" Text="Button 2" /></td>
<td><asp:TextBox ID="textBox2" runat="server" Text="StartText" Enabled="false" /></td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanelReset" runat=server>
<ContentTemplate>
<asp:Button ID="reset" runat="server" OnClick="Reset_click" Text="reset" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="button1" EventName="click" />
<asp:AsyncPostBackTrigger ControlID="button2" EventName="click" />
</Triggers>
</asp:UpdatePanel>
</asp:Content>
The code behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_click(object sender, EventArgs e)
{
textBox1.Enabled = !textBox1.Enabled;
reset.Enabled = !textBox1.Enabled && !textBox2.Enabled;
}
protected void Button2_click(object sender, EventArgs e)
{
textBox2.Enabled = !textBox2.Enabled;
reset.Enabled = !textBox1.Enabled && !textBox2.Enabled;
}
protected void Reset_click(object sender, EventArgs e)
{
textBox1.Text = "StartText";
textBox2.Text = "StartText";
label1.Text = "reset button clicked";
}
}
}
Just add a PostBackTrigger to the last UpdatePanel.
<asp:PostBackTrigger ControlID="reset" />