Showing posts with label aspx. Show all posts
Showing posts with label aspx. Show all posts

Wednesday, March 28, 2012

Asp.net Ajax Enabled web app creating more ScriptResource.axd on a Simple page

Hello,

I am using Asp.net Ajax extension 1.0.In my application ,I am using a index.aspx page,which have no script manager control.When i am runing this application the the index page is loading very slow.When I save the page from browser I am finding six ScriptResource.axd files are loading on client side.Which have up to 400 kb.So I want to reduce these files on index page.But I do not know how I do it.Please help me.

Regards,

Pawan

Hi Pawan,

Basically, those scripts won't be requested if there is no AJAX related controls on the form.
If you are using MasterPage and there is ScriptManager on it, they will be downloaded too.

Hope this helps.

Hello Raymond Wen,

Thanks for reply.

I am using asp.net ajax enable website1.0.I have noticed that ScriptResource.axd is uploaded each time when I am navigate the site.On each page ScriptResource.axd is again loading.I want to cache ScriptResource.axd on Client Side.If you have any idea about it then please help me. Thanks & Regards, Pawan


Please try the following:

1. Set debug to false in web.config

2. Set ScriptMode property of the ScriptManager to release


These should be cached on the client as long as you have <Compilation Debug="false" /> in your web.config.

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 Ajax : how to write javascript code in .cs file?

my code :

aspx:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="btnCheck_Click" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>

.CS file:

protected void btnCheck_Click(object sender, EventArgs e)
{
string script = "<script>alert('test');</script>";
Response.Write(script);
this.Label1.Text = "error";
}

but it's throw javascript exception when i run it .how to write javascript code in .cs file?

Well, your best option is "don't". But if you must, then use the ScriptManager functions for registering scripts and script blocks.They're in the documentation.


here is yours as a working example

the .aspx. Have a look at buttons client eventOnClientClick

<asp:ScriptManager ID="sm1" runat="server" /><asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="Test()" /></ContentTemplate></asp:UpdatePanel>

the codebehind

protected override void OnInit(EventArgs e){if (sm1.SupportsPartialRendering){sm1.EnablePartialRendering =true;}string script ="function Test() {alert('Hello');}";ScriptManager.RegisterClientScriptBlock(this,typeof(Page),"Test", script,true);base.OnInit(e);}protected void Page_Load(object sender, EventArgs e){}

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!

asp.net 1.1 ajax and xml

I'm trying to implement ajax on some of my forms by having an aspx page write out xml. I'm building the xml using a string builder and useing response.contentType = "text/xml" followed by response.write at the end. If I just display the page, it renders it as xml with all the right nodes and values which is cool, but when I call xmlDoc = xmlHttp.responseXML, I'm not getting any childnodes.

The same code works if I call an xml file as the src of the ajax call.

This is my first real crack at implementing this so if anyone has any ideas, I'm open. If I'm way off, let me know.

Thanks

Dave

I wound up getting this to work by adding ContentType="text/xml" to the page directive of my xml producing aspx page.

Here's the code that rendered the xml.

Public Sub GetResponse() Response.ContentType ="text/xml"Dim strVars()As String = {"one","two","three","four","five","six","seven","eight","nine","ten"}Dim strItemVals()As String Dim sbAs New StringBuilderDim counterAs Integer = 0Dim maxAs Integer = 10Dim loXmlAs New XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8) loXml.WriteStartDocument() loXml.WriteStartElement("Response")For Each strAs String In strVarsIf counter < maxThen'Write Code via xml loXml.WriteStartElement(str)loXml.WriteString(str &" - Content") loXml.WriteEndElement() counter += 1Else Exit For End If Next loXml.WriteEndElement() loXml.WriteEndDocument() loXml.Close()End Sub

ASP.NET ~ Path substitution wrong

I am passing parameters around a site in the URL by using page.aspx/value in the URL instead of page.aspx?key=value

The problem I am running into is ~ doesn't work.

Say I'm in a page such as "foldera/folderb/default.aspx/value" and it uses an image referenced as "~/image.jpg"

The correct location is "/foldera/folderb/image.jpg"
Instead the location is being rendered as "/foldera/folderb/default.aspx/image.jpg"


Within my own code, this is A-OK, I can subsitute by hand quite easily. The problem comes in the AjaxControlKit, which references images and scripts using "~/WebResource.axd" but i'm getting "default.aspx/WebResource.axd" which of course is a problem, since its not referencing the script and image IIS extension, but is instead accessing the page it called from.


Does anyone have a good solution? It has been quite common in my apps to use fake URLs to pass parameters because it is search engine friendly but this one has me stuck. I know AjaxControlKit has its source code available, but I don't want to have to modify the code for something so dumb...

Maybe there is a way to override the URL parsing? (probably not, but had to ask)

Dan

Do you have some url rewriting engine driving ur parameterised urls? It seems like that must be where your parsing difficulties are occurring. I use url rewriting and it doesn't screw with "~".


Sounds like a bug. Are you parsing the url "yourself" to get at the values or are you using RewritePath? If you're not using RewritePath it might be a good idea to do that.


I don't use any form of URL rewriting...the Tail is automatically ignored by ASP.NET and IIS for delivering the page...

I read the Page URL during my state class's creation during each pages PreInit() method, and all it does is a quick non-destructive parse looking for expected values after the page.aspx/

My understanding of using the rewriting functions is they cause a transparent redirect...

I just want ASP.NET to render properally; after all it knew what page to actually load with the tail...


You shouldn't have to, but right now I think you'll have to implement rewriting. That way, your page will think it's called as page.aspx?key=val, and the url resolving should not fail.

I actually think it's a much cleaner approach than parsing the url in PreInit.

ASP.NET / Ajax asp:UpdatePanel controls

I am just getting started using the ASP.NET/Ajax extensions and am curious about something. I have an aspx page where the controls are laid out using a table...nothing unusual there. Two of the controls are asp:DropDownList controls. Each of the controls appears in a row <tr> of the enclosing <table>. I have the classic issue of having the selection of DropDown1 controlling the choices listed in DropDown2. I need then to put the DropDown2 in an UpdatePanel and wire them together. However, can you use the UpdatePanel INSIDE of the <table> around only those rows containing the control involved? Something like this...(I have not completed this yet...as I wanted to find out if this is even allowed).

<tr>
<td align="right">
<asp:Label ID="lblSYS_NM" runat="server" Text="System:"></asp:Label></td>
<td>
<asp:DropDownList ID="ddSYS_NM" runat="server" >
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvddSYS_NM" ControlToValidate="ddSYS_NM" InitialValue="0" Display="Dynamic" runat="server">
<%= RequestConstants.DDL_MSG %>
</asp:RequiredFieldValidator>
</td>
<td>
(Select System)</td>
</tr>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<tr>
<td align="right">
<asp:Label ID="lblSUB_SYS_NM" runat="server" Text="SubSystem:"></asp:Label></td>
<td>
<asp:DropDownList ID="ddSUB_SYS_NM" runat="server" AutoPostBack="False">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvddSUB_SYS_NM" ControlToValidate="ddSUB_SYS_NM" InitialValue="0" Display="Dynamic" Width="100%"
runat="server">
<%= RequestConstants.DDL_MSG %>
</asp:RequiredFieldValidator>
</td>
<td>
(Select SubSystem)</td>
</tr>
</ContentTemplate>

<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddSYS_NM" EventName="SelectedIndexChanged" />
</Triggers
</asp:UpdatePanel>

Thanks

I would only wrap the necessary controls with the update panel. The only thing that changes within the update panel is the DropDownLists. it would look more like this:

<table>
<tr>
<td><asp:Label... /></td>
<td>
<asp:DropDownList id="DropDown1" .../>
<asp:RequiredFieldValidator .../>
</td>
</tr>
<tr>
<td><asp:Label... /></td>
<td>
<asp:UpdatePanel ...>
<ContentTemplate>
<asp:DropDownList id="DropDown2" .../>
<asp:RequiredFieldValidator .../>
</ContentTemplate>
<Triggers>
<AysncPostBackTigger Control="DropDownList1" Event="Click" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>

Wednesday, March 21, 2012

ascx and ajax

HTML Source EditorWord wrap

Hi!

I am using an chat control (ascx) on my aspx sites. Any user can post a message and press the 'Absenden' button. After that the message will be send to database through code behind. The Gridview will be updated after this. Now I am trying to change the code (to ajax) so that there is 'no' postback on clicking on the 'Absenden' button. I have just watched the video on introducing ajax and sofar i am not quite sure what to do - placing a script manager ? placing an update panel? Thanks in advance for your help!!

ASCX Code

<%@dotnet.itags.org.ControlLanguage="C#"AutoEventWireup="true"CodeFile="ajaxLaberbox.ascx.cs"Inherits="Steuerelemente_laberbox" %>
<%@dotnet.itags.org.RegisterAssembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"Namespace="System.Web.UI"TagPrefix="asp" %>
<tableborder="0"width="150">
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<tdclass="ueberschrift3"align="center">Die LOW-Laberbox</td>
</tr>
<tr>
<tdheight="1"> </td>
</tr>
<tr>
<tdheight="1">
<asp:LabelID="lblNachricht"runat="server"Text="Deine Nachricht"CssClass="ueberschrift3"></asp:Label>
</td>
<tr>
<tdalign="center"height="1"><asp:TextBoxID="txtNachricht"runat="server"Height="87px"BorderColor="Transparent"ForeColor="Black"TextMode="MultiLine"MaxLength="400"Width="160px"></asp:TextBox>
</td>
</tr>
<tr>
<tdalign="center"height="1"><asp:ButtonID="btnAbsenden"runat="server"Text="Absenden"BackColor="#EDC112"BorderWidth="0px"Font-Names="Tahoma"Font-Size="8pt"OnClick="btnAbsenden_Click"/>
</td>
</tr>
<tr>
<tdnowrap>
<asp:GridViewID="gvNachrichten"runat="server"AutoGenerateColumns="False"DataSourceID="dbNachrichten"GridLines="None"Width="175px">
<Columns>
<asp:BoundFieldDataField="text"HtmlEncode="False"SortExpression="text">
<ControlStyleWidth="150px"/>
<ItemStyleWidth="150px"Wrap="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>
<asp:SqlDataSourceID="dbNachrichten"runat="server"ConnectionString="<%$ ConnectionStrings:dbLOWConnectionString %>"
SelectCommand="SELECT top 10 '<span class="ueberschrift3">' + benutzer + ': </span><font size="-2" color="#EDC112">(' + DATENAME(d, datum) + '.' + convert(varchar(3), DATEPART(m, datum)) + '. ' + DATENAME(hh, datum) + ':' + DATENAME(mi, datum) + ')</font><span class="normal"> ' + nachricht + '</span>' AS text FROM tblNachrichten order by id desc">
</asp:SqlDataSource>
</td>
</tr>
</table>

The page that contains that control will need to have scriptmanager tag in it. The contents of your control (After the <%@. Register %>) need to be in an update panel of its own or you could place the control in an update panel inside of the Page.

Here is a link to some code to paste inside of the control that will dynamically add a scriptmanager and add all of the controls contents to an update panel.http://forums.asp.net/t/1090648.aspx?PageIndex=2


I found the problem! Unfortunatelly it was something completly different. My project was a simple ASP.Net Website. So in myweb.configmissed all necessarytags for ajax (see below)!! Thx to Joseh Humphrey - additionally i had to add the script manager in the page not in the control!

<config section>
<httpHandlers>
<system.webServer>
and so on

IT WORKS! :-)