Can anyont point me to a code sample where a call is made to a server page method from the client script code?
thanks!
Pratibha
Hi,please checkthis post from my blog.
Can anyont point me to a code sample where a call is made to a server page method from the client script code?
thanks!
Pratibha
Hi,please checkthis post from my blog.
I understand that a script with the pageLoad() function is a way to hook into the client side load event.
That works great if you are working in the .aspx page itself. What if you're in a user control and want something to hook into the pageLoad() event on the client?
I could use Page.RegisterClientScriptBlock() to inject the JS into the page, but that would overwrite any other function that might be in the master page, content page or other user controls.
Isn't there a way to just add an event to the page load on the client side and not worry about conflicting with other code?
Thanks,
John
Can you give an example of what you're trying to do?
You can add your own pageLoad() handler by usingSys.Application.add_load().
HI,
I could use the page_load server event, but that would delay the rendering of the entire page until this process is complete. The effect I am looking for is to render a page so the user has something to look at. Then, when theclient on_load event fires, initiate some long running tasks that can take place while the user already has something to look at.
Thanks,
John
Sys.Application.Load is the client side event, not server side. Take a look at the documentation I linked. That's the event that pageLoad() calls implicitly.
Hi,
In the User control , write this function ,
<script>
function IAMIntheUserControl(object,eventArgs) {
}
</script>
register this script with RegisterClientScriptBlock.
Sys.Application.add_load( IAMIntheUserControl );
Hello,
I have the next issue in my web application.
On server i'm sending to the client during a server event with registerdataitem a string -an url.
On client in pageloading i'm getting the url and showing into a popup window. This is the code:
var
wind=null;var
currenturl=null;var
i=0;Sys.Application.add_load(ApplicationLoadHandler);
function
ApplicationLoadHandler(sender, args){
//Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(pageLoadingHandler)
}
//function EndRequestHandler(sender, args)
function
pageLoadingHandler(sender, args){
var dataItems = args.get_dataItems();wind=document.getElementById(
'popupid');if (wind!=null)return;if (document.title.indexOf("Print")>=0)currenturl=dataItems[
'ctl00_currenturl'];elsecurrenturl=dataItems[
'currenturl']if (currenturl !=null )//show the popup{
wind=window.open(currenturl,
'popupid');//DeleteFile(dataItems['currenturl']);works fine only on ie this solution
}
}
The problem is that the ajax pagerequestmanager event is raised too many times making the popup to be created to many time and sometimes browser to run out of resources.
How could i fix it i mean the pagerequestmanager event to be raised normaly i mean once.
I 'm using ie 6.5
Thanks
Hi,
Please use try this code snippet:
Sys.Application.add_load(ApplicationLoadHandler)
function ApplicationLoadHandler(sender, args)
{
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (!prm.get_isInAsyncPostBack())
{
prm.add_pageLoading(pageLoadingHandler);
}
}
Hope this helps.
I have some JScript that is utilized by a custom TextBox control that does various validation and format functions on the client side. In particular, when the control receives focus I left-justify the value in the textbox and format it without currency and grouping characters. Just the raw number. Then when the control loses focus (blur), I re-format the contents based on a property that indicates which formatting to use. This custom TextBox accepts only numeric input. In the case of a curreny input (DisplayFormat = "C") and a negative number, the number is formatted using the current culture's CurrencyNegativePattern of CultureInfo.NumberFormat. AJAX handles all of this for me since I call the Number.localeFormat function. The problem is that when the TextBox receives focus, I try to strip all formatting to get the raw number but for a negative currency value AJAX'sparseLocale function does not recognize the parantheses that are added to the number when it is formatted bylocaleFormat. Example: -1000 is formatted as ($1,000.00) with a format string of "C2" but when you pass this toparseLocale you get "1000.00". Shouldn'tparseLocale recognize the negative patterns its counterpartlocaleFormat adds to the value?
function numberEditorFocus(src)
{
src.style.textAlign ='left';
var displayFormat ="D";
if (src.value !="")
{
var val = Number.parseLocale(stripCurrency(src.value));
alert(val);
if (isNaN(val) ==false)
{
var newValue = val.localeFormat(displayFormat);
src.value = newValue;
}
src.select();
}
}
Sounds like it may be a bug, take a look in the source code for the AJAX Framework or theissues list
-Damien
Nothing in the bug list. It's obvious from the source code in the AJAX library that the parseLocale (and subsequently the parse) function does not consider the negative currency pattern. It only accounts for the preceding +/- sign. So, is this a bug or is there some reason it was designed with way? AJAX team?
Number.parseLocale = function Number$parseLocale(value) { /// <param name="value" type="String"></param> /// <returns type="Number"></returns> var e = Function._validateParams(arguments, [ {name: "value", type: String} ]); if (e) throw e; return Number._parse(value, Sys.CultureInfo.CurrentCulture);}Number.parseInvariant = function Number$parseInvariant(value) { /// <param name="value" type="String"></param> /// <returns type="Number"></returns> var e = Function._validateParams(arguments, [ {name: "value", type: String} ]); if (e) throw e; return Number._parse(value, Sys.CultureInfo.InvariantCulture);}Number._parse = function Number$_parse(value, cultureInfo) { var valueStr = value.trim(); if (valueStr.match(/infinity/i) !== null) { return parseFloat(valueStr); } if (valueStr.match(/^0x[a-f0-9]+$/i) !== null) { return parseInt(valueStr); } var numFormat = cultureInfo.numberFormat; var decSeparator = numFormat.NumberDecimalSeparator; var grpSeparator = numFormat.NumberGroupSeparator; var numberFormatRegex = new RegExp("^[+-]?[\\d\\" + grpSeparator + "]*\\" + decSeparator + "?\\d*([eE][+-]?\\d+)?$"); if (!valueStr.match(numberFormatRegex)) { return Number.NaN; } valueStr = valueStr.split(grpSeparator).join(""); valueStr = valueStr.replace(decSeparator, "."); return parseFloat(valueStr);}
I'd modify the source and recompile for now so that it works for you, and I would log this as a bug...
-Damien
This might sound silly, but I can't work out how to get the server to be able to send back some javascript to the client to run during a partial page render. I've tried scriptmanager and clientscriptmanager functions, but that doesn't seem to work. Partial page rendering doesn't seem to like response.write, and if I put the code inside a literal, I think that the AJAX framework doesn't process it. Am I missing something?
Thanks,
Martin
Hi,
could you post the code that is causing problems?
Hi,
I changed the asp.net applicaiton to ajax enable asp.net but update panal is not working. When button is clicked its doing full page refresh. When I looked at the view source script manager is not being fired.
<!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="TestPage1.aspx" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTEzMjQ1MTY4NjFkZMnkklM4zF7XCrNB+Ckg0ltF70NO" />
<script src="http://pics.10026.com/?src=http://forums.asp.net/wow/Clinic/ScriptResource.axd?d=JyTA_qOIT3R2dUV6rZPpnB4caeUfuYVxGPUJUQvFvri3YW3Aua3OVlokWHAQU8raiEpmo7HCzcrEB7ckCqw8DDX6XbV0NlaftMuueWAwHqQ1&t=633068891263750000" type="text/javascript"></script>
<div id="UpdatePanel1">
<input type="submit" name="Button1" value="Button" id="Button1" />
<input name="TextBox1" type="text" value="3/9/2007 4:40:24 PM" id="TextBox1" />
</div>
<input name="TextBox2" type="text" value="3/9/2007 4:40:24 PM" id="TextBox2" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBALb7diADgKM54rGBgLs0bLrBgLs0fbZDL3mTY/JT5nhMoKiVWH9R12nFdZZ" /><script type="text/javascript">
<!--
Sys.Application.initialize();
// -->
</script>
</form>
</body>
</html>
webcofig file:
<?xml version="1.0"?>
<configuration>
<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>
<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>
<!--
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.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Oracle.DataAccess, Version=10.2.0.100, Culture=neutral, PublicKeyToken=89B483F429C47342"/>
<add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.OracleClient, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
</compilation>
<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-Integrated"/>
<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>
code behind:::
PartialClass Intake_TestPage1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox2.Text = Date.Now
End Sub
Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As System.EventArgs)
TextBox1.Text = Date.Now
End Sub
End Class
Does anyone knows whats causing this problem....no partial page update?
Hello, thank you in advance for taking the time to read this.
I have a Gridview on which I use client-side JScript to add an empty row (hidden) after binding. I place several hidden DIVS in my Gridview template, and then when a user clicks on one of several "expand" buttons in the Gridview, the empty row is made visible and the innerHTML is swapped from the appropriate hidden DIV. This makes the empty row sort of a "Jack of all trades" in that it can display numerous different things as needed by the user.
I am attaching the JScript function below for reference. The empty DIVS are inserted into the client page in the Codebehind using the Gridview's OnRowDataBound handler, but I have no clue how to add a row dynamically server-side, so I went with the client-side script to get the container row done.
Everything works great until you do a sort. The control is AJAX-enabled, so refreshes through a partial postback. Trouble is that the client-side code that adds all the rows does not fire when the grid is refreshed, so none of the "Expand" icons work after the Gridview has been refreshed, because there is no hidden row to make visible and swap content with.
After all this, my question is: How might I:
A) insert an empty row programatically server-side, or
B) fire a client-side script at databinding on a partial postback.
Oh, and I am a pure short-busser when it comes to .NET -- love it but am just now moving up from legacy and feel like a complete idiot. Please speak slowly if you care to answer, and forgive my ignorance.
Javascript adding the rows follows -- I am assigning an ID reference to each row using the "Tracking" field - a unique DB column.
Thanks again for reading, and for any information or hlp you can provide.
Shannon
function fixGrid(idGrid){
var al ="";
var rowcount = 0;for (var t=0;t<idGrid.childNodes[0].childNodes.length-1;t++){thisName = idGrid.childNodes[0].childNodes[t].nodeName;
if(thisName=="TR"){rowcount ++;
if(rowcount > 1){lastCell = idGrid.childNodes[0].childNodes[t].childNodes.length;
thisCell = idGrid.childNodes[0].childNodes[t].childNodes[lastCell-1];
thisTrack = idGrid.childNodes[0].childNodes[t].childNodes[lastCell-2].innerText;
newTR = document.createElement('tr');newRow1 = newTR.cloneNode(true);
newTD = document.createElement('td');newCol1 = newTD.cloneNode(true);newCol1.colSpan=9;
newCol1.style.visibility='hidden';
newCol1.style.display='none';newCol1.id ="td-"+thisTrack;
newCol1.innerHTML="Nothing";newTR.appendChild(newCol1);
nextRow = idGrid.childNodes[0].childNodes[t].nextSibling;
tableTop = idGrid.childNodes[0].childNodes[t].parentNode;
tableTop.insertBefore(newTR,nextRow);
t++;
}
}else{
alert(thisName);
}
}
returnfalse;
}
Problem solved! I figured I would answer myself for the benefit of future readers.
The call to the client side code in my original post is made fromfixGrid(document.all.gridedit)when the page originally loads.
Obviously, I only want to add the empty container rows once, so I only want this script to be called once each time UpdatePanel1 refreshes, and not if any other panel does. Got it to work that way usingRegisterClientScriptBlock with the update panel ID:
protectedvoid Page_PreRender(object sender,EventArgs e)
{
string script =@."fixGrid(document.all.gridedit);";ScriptManager.RegisterClientScriptBlock(UpdatePanel1,
typeof(Page),
"ToggleScript",script,
true);}
When we do a full postback, the page's client script registers a startup script like the one below, however, on a partial postback the script is not registered. Since the script is not registered, our calendars fail to initialize and are not usable. Any help would be appreciated. Thanks!
string StartCalendarJS ="var calStart0 = new js_calendar(document.getElementById('" + StartDateTextBox.ClientID +"'));";StartCalendarJS +=
"calStart0.year_scroll = true;";StartCalendarJS +=
"calStart0.time_comp = false;";cs.RegisterStartupScript(cs.GetType(),
"CsStartDate", StartCalendarJS,true);StartDateCal.Attributes.Add(
"onclick","javascript:calStart0.popup();");StartDateCal.Attributes.Add(
"onMouseOver","this.style.cursor='hand';");I would also like to share that the code above is being executed during the DataBound function of a gridview which includes the calendar we are trying to implement. Thanks.Try,
System.Web.UI.ScriptManager.RegisterClientScriptBlock(.........);
Aeries
Any answer to this yet? Perhaps this is fixed in the latest version? We are using the Nov. 2006 release.
Any information would be great.
Thanks
Partial Update,ajax