Showing posts with label fromhttp. Show all posts
Showing posts with label fromhttp. Show all posts

Monday, March 26, 2012

ASP.NET Ajax beginner question

Hi all,
I followed first walk through sample from
http://ajax.asp.net/docs/tutorials/IntroductionUpdatePanel.aspx to create my first testing page, The problem is after I clicked that botton, it still trigged a postback. Do I miss something?

Following is my code:

ASPX Page

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %
<%@dotnet.itags.org. Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Parcel created"></asp:Label>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html
Code behind

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e) {
Label1.Text = "Refreshed at " + DateTime.Now.ToString();
}
}

Html code generated by page

<!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><title>
Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwULLTEyNTU5OTE4NDBkZFFbG+xINimfJjnJzMPyN5/bdPcr" />
</div
<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script
<script
src="http://forums.asp.net/AjaxSandbox/WebResource.axd?d=uPSIJPV09GNZkXa1aWLuZA2&t=632961560341637622" type="text/javascript"></script
<script
src="http://forums.asp.net/AjaxSandbox/ScriptResource.axd?d=Rdf9isNeXMPi-qNzO-XVRmXNOH0DmLQG-4RxW5WORPfrZ2K0YD5Icg_Bz9c5f0-wuytwMMng0hZa1k1SSKrW5yqEjrhREy__cV5gKfSghPU1&t=633053156500271737" type="text/javascript"></script>
<script
src="http://forums.asp.net/AjaxSandbox/ScriptResource.axd?d=Rdf9isNeXMPi-qNzO-XVRmXNOH0DmLQG-4RxW5WORPfrZ2K0YD5Icg_Bz9c5f0-wuytwMMng0hZa1k1SSKrW572e2ypQhyGf_JtyUNuUy11_drtp-tXJrGLYVAgwBUoK0&t=633053156500271737" type="text/javascript"></script>
<div>
<script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ScriptManager1',
document.getElementById('form1'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tUpdatePanel1'], [], [], 90);
//]]>
</script
<div id="UpdatePanel1"
<span id="Label1">Parcel created</span>
<input type="submit" name="Button1" value="Button" id="Button1" /
</div>
</div>

<div
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION"
value="/wEWAgLk5+S6DwKM54rGBofhZslYBM4FNpmEHJadJ6r8Aq3Z" />
</div
<script type="text/javascript">
<!--
Sys.Application.initialize();
// -->
</script>
</form>
</body>
</html>

Hey,

For your script manager, add EnablePartialRendering="true", and for your updatepanel, add Mode="Always".


Neither of those things should be necessary. (They're both the defaults.) Also, it's "UpdateMode" now (not "Mode" as it was in early CTPs).

My guess is that something's wrong in your web.config... did you start from the "ASP.NET AJAX-Enabled Web Site" template? Are there any JavaScript errors on the page when you first load it?


Steve Marx:

Neither of those things should be necessary. (They're both the defaults.) Also, it's "UpdateMode" now (not "Mode" as it was in early CTPs).

My guess is that something's wrong in your web.config... did you start from the "ASP.NET AJAX-Enabled Web Site" template? Are there any JavaScript errors on the page when you first load it?

You are right, I didn't start a new web site with "ASP.NET AJAX-Enabled Web Site" template. I adjusted web.config manually, and it works.

Saturday, March 24, 2012

ASP.NET 2003 can use AJAX?

Split off fromhttp://forums.asp.net/t/1118842.aspx by moderator XIII:

pls kindly send me steps for adding the Ajax tool kit to visual studio 2003..

kindly help me asap..

I have a problem i.e i have two textboxes and a chechbox.

if i check the checkbox then the value of textbox1 should be transferred to textbox2 so.. i need this is to be written using client side as well as the data should be stored in the database..

so can v do this using AJAX.. how is it possible

vijai

As the MVP said at http://forums.asp.net/t/1118842.aspx:

No. Visual Studio 2003 is specifically made to work with .NET 1.1. If you want to use ASP.NET AJAX you need to use Visual Studio 2005 or the free Visual Web Developer Express tool to use the server side components. If however you only need the client scripts, download the Microsoft AJAX Library and include them in your ASP.NET 1.1 pages like you would with any other external .js file.

So what you could do is create your webservices with the free VWD tool, integrate ASP.NET AJAX into them, deploy them and use the client scripts from the Microsoft AJAX Library in your ASP.NET 1.1 pages to call those webservices. You won't have access to the UpdatePanel or related server controls but you can use the client side behavior of ASP.NET AJAX in your pages today which will make it much easer later on to upgrade your application to ASP.NET 2.0.


True that you cannot use the ASP.NET AJAX Extensions from ASP.NET 1.x, but not entirely. TheMicrosoft AJAX Library (which is the JavaScript library that ASP.NET AJAX Extensions uses) can be used with any server-side platform, because it is just another client-side JavaScript AJAX library.

I'm sure they were meaing to use the full AJAX Extension within ASP.NET 1.x with all the UpdatePanel goodness, so sorry you have to upgrade to .NET 2.0. But at least it's free to upgrade, just go download the Visual Web Developer Express and get Ajaxifying!