 |
BOOK: Professional ASP.NET 2.0 AJAX ISBN: 978-0-470-10962-5  | This is the forum to discuss the Wrox book Professional ASP.NET 2.0 AJAX by Matt Gibbs, Dan Wahlin; ISBN: 9780470109625 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Professional ASP.NET 2.0 AJAX ISBN: 978-0-470-10962-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

October 31st, 2007, 09:18 AM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Button posts back
I noticed that when I run the code from example 2-1, both buttons post back. I used the code from the download and have the AJAX Extensions installed. Any ideas why button1 is posting back?
Here's the code, just in case...
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" language="C#" >
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
string theTime = DateTime.Now.ToLongTimeString();
for (int i = 0; i < 3; i++) {
theTime += "<br />" + theTime;
}
time1.Text = theTime;
time2.Text = theTime;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Basic Update Panel</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:Label runat="server" ID="time1"></asp:Label><br /><br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div style="border-style:solid;background-color:gray;">
<asp:Label runat="server" ID="time2"></asp:Label><br />
<asp:Button ID="Button1" runat="server" Text="Inside Button" />
</div><br />
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="Button2" runat="server" Text="Outside Button" />
</div>
</form>
</body>
</html>
|
|

October 31st, 2007, 11:06 AM
|
|
Registered User
|
|
Join Date: Oct 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I found my own problem. Correct me if I'm wrong, but the book does not describe implementing the Web.config file prior to this example. After using the correct file, the page updated correctly.
I have a new question though. How do I integrate this into an existing website? I tried combining the two Web.config files, but the page still posts.
Web.config file...
Code:
<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<sectionGroup name="system.web.extensions"
type="System.Web.Configuration.SystemWebExtensionsSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting"
type="System.Web.Configuration.ScriptingSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler"
type="System.Web.Configuration.ScriptingScriptResourceHandlerSection,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
requirePermission="false"
allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices"
type="System.Web.Configuration.ScriptingWebServicesSectionGroup,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization"
type="System.Web.Configuration.ScriptingJsonSerializationSection,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
requirePermission="false" allowDefinition="Everywhere" />
<section name="profileService"
type="System.Web.Configuration.ScriptingProfileServiceSection,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
requirePermission="false"
allowDefinition="MachineToApplication" />
<section name="authenticationService"
type="System.Web.Configuration.ScriptingAuthenticationServiceSection,
System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
requirePermission="false"
allowDefinition="MachineToApplication" />
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<connectionStrings>
<add name="ADConnectionString" connectionString="REMOVED"/>
<add name="DailyLogString" connectionString="REMOVED" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>
<customErrors mode="Off"/>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<!-- <authentication mode="Forms">
<forms loginUrl="login.aspx" name=".ADAuthCookie" timeout="60" path="/">
</forms>
</authentication> -->
<authentication mode="Windows" />
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
<membership defaultProvider="MyADMembershipProvider">
<providers>
<add name="MyADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, #xA; Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" attributeMapUsername="sAMAccountName" connectionStringName="ADConnectionString" connectionUsername="REMOVED" connectionPassword="REMOVED"/>
</providers>
</membership>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
</system.web>
<system.web.extensions>
<scripting>
<webServices>
<!-- Uncomment this line to customize maxJsonLength and add a
custom converter -->
<!--
<jsonSerialization maxJsonLength="500">
<converters>
<add name="ConvertMe"
type="Acme.SubAcme.ConvertMeTypeConverter"/>
</converters>
</jsonSerialization>
-->
<!-- Uncomment this line to enable the authentication service.
Include requireSSL="true" if appropriate. -->
<!--
<authenticationService enabled="true" requireSSL = "true|false"/>
-->
<!-- Uncomment these lines to enable the profile service. To
allow profile properties to be retrieved
and modified in ASP.NET AJAX applications, you need to add
each property name to the readAccessProperties and
writeAccessProperties attributes. -->
<!--
<profileService enabled="true"
readAccessProperties="propertyname1,propertyname2"
writeAccessProperties="propertyname1,propertyname2" />
-->
</webServices>
<!--
<scriptResourceHandler enableCompression="true"
enableCaching="true" />
-->
</scripting>
</system.web.extensions>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<add name="ScriptModule"
preCondition="integratedMode"
type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-ISAPI-2.0"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx"
preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*"
path="*_AppService.axd" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" preCondition="integratedMode"
verb="GET,HEAD" path="ScriptResource.axd"
type="System.Web.Handlers.ScriptResourceHandler,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>
</configuration>
aspx file...
Code:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="section">
<asp:CustomValidator ValidationGroup="Main" ID="WRSEGroup" runat="server" ErrorMessage="You must click Add to add the WRS Employee" Text="*" Display="Dynamic" OnServerValidate="WRSEGroup_ServerValidate"></asp:CustomValidator>
WRS Employees
<asp:ValidationSummary ValidationGroup="WRSE" ID="ValidationSummary2" runat="server" />
<asp:SqlDataSource ID="WRSESource" runat="server" ConnectionString="<%$ ConnectionStrings:DailyLogString %>"
DeleteCommand="DELETE FROM [WRSEmployee] WHERE [ID] = @ID"
InsertCommand="INSERT INTO [WRSEmployee] ([LogID], [firstName], [lastName], [wrsHours], [wrsPosition]) VALUES (@LogID, @firstName, @lastName, @wrsHours, @wrsPosition)"
SelectCommand="SELECT * FROM [WRSEmployee] WHERE ([LogID] = @LogID)"
UpdateCommand="UPDATE [WRSEmployee] SET [firstName] = @firstName, [lastName] = @lastName, [wrsHours] = @wrsHours, [wrsPosition] = @wrsPosition WHERE [ID] = @ID">
<SelectParameters>
<asp:ControlParameter ControlID="LogIDText" Name="LogID" PropertyName="Text" Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="LogID" Type="Int32" />
<asp:Parameter Name="firstName" Type="String" />
<asp:Parameter Name="lastName" Type="String" />
<asp:Parameter Name="wrsHours" Type="int32" />
<asp:Parameter Name="wrsPosition" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<div class="sectcontent">
<table>
<tr>
<td>
Add a WRS Employee
</td>
</tr>
<tr>
<td>
<asp:DropDownList ID="dropdownWRS" runat="server" AutoPostBack="true" DataSourceID="WRSDrownDownSource" OnSelectedIndexChanged="dropdownWRS_IndexChanged" DataTextField="Name" DataValueField="Name">
</asp:DropDownList>
<asp:SqlDataSource ID="WRSDrownDownSource" runat="server" ConnectionString="<%$ ConnectionStrings:DailyLogString %>"
SelectCommand="SELECT DISTINCT lastName + ', ' + firstName AS Name FROM [WRSEmployee]"></asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
First Name:
</td>
<td>
<asp:RequiredFieldValidator ValidationGroup="WRSE" ID="WRSEFirstName" runat="server" ErrorMessage="You must enter a first name" Text="*" Display="Dynamic" ControlToValidate="firstNameWRS"></asp:RequiredFieldValidator>
<asp:TextBox ID="firstNameWRS" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Last Name:
</td>
<td>
<asp:RequiredFieldValidator ValidationGroup="WRSE" ID="WRSELastName" runat="server" ErrorMessage="You must enter a last name" Text="*" Display="Dynamic" ControlToValidate="lastNameWRS"></asp:RequiredFieldValidator>
<asp:TextBox ID="lastNameWRS" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Hours:
</td>
<td>
<asp:RequiredFieldValidator ValidationGroup="WRSE" ID="WRSEHours" runat="server" ErrorMessage="You must enter the hours worked" Text="*" Display="Dynamic" ControlToValidate="hoursWRS"></asp:RequiredFieldValidator>
<asp:TextBox ID="hoursWRS" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Position:
</td>
<td>
<asp:RequiredFieldValidator ValidationGroup="WRSE" ID="WRSEPosition" runat="server" ErrorMessage="You must enter the employee position" Text="*" Display="Dynamic" ControlToValidate="positionWRS"></asp:RequiredFieldValidator>
<asp:TextBox ID="positionWRS" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="vertical-align:bottom; background-color:Maroon; color:White;" colspan="2">
<asp:Button ID="addWRSEmployee" runat="server" Text="Add" OnClick="addWRSEmployee_Click" Font-Bold="true" BackColor="Blue" ForeColor="Blue" />
You must click "Add" to add the WRS Employee
</td>
</tr>
</table>
<table>
<tr>
<td>
<asp:GridView ID="WRSEmployees" runat="server" AutoGenerateEditButton="true" AutoGenerateDeleteButton="true" AutoGenerateColumns="False" DataSourceID="WRSESource" DataKeyNames="ID">
<Columns>
<asp:BoundField DataField="firstName" HeaderText="First Name" SortExpression="firstName" />
<asp:BoundField DataField="lastName" HeaderText="Last Name" SortExpression="lastName" />
<asp:BoundField DataField="wrsHours" HeaderText="Hours" SortExpression="wrsHours" />
<asp:BoundField DataField="wrsPosition" HeaderText="Position" SortExpression="wrsPosition" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
|
|

January 3rd, 2009, 11:12 PM
|
|
Registered User
|
|
Join Date: Dec 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
1. Add the click event for button1 as below
<asp:Button ID="Button1" runat="server" Text="Inside Button" OnClick="button1_click"/>
2. Implement the click event as at server side
private void button1_click(object sender, EventArgs e)
{
string theTime = DateTime.Now.ToLongTimeString();
for (int i = 0; i < 3; i++)
{
theTime += "<br />" + theTime;
}
time2.Text = theTime;
}
3. put all the code in is not post back condition at page load event
as below
if (!IsPostBack)
{
string theTime = DateTime.Now.ToLongTimeString();
for (int i = 0; i < 3; i++)
{
theTime += "<br />" + theTime;
}
time1.Text = theTime;
time2.Text = theTime;
}
|
|
 |