|
How about doing a bit of recursion? You don't call the remote method inside a loop, but instead the callback function keeps calling RS.Execute until the last iteration is reached -- something like this:
function callback(result, index)
{
...
if (index < 100)
RS.Execute("page.aspx", "RemoteMethod", ..., callback, index + 1);
}
Regards,
Alvaro
Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is. -- GWB, 1999.
|
|
|
|
|
Alvaro,
Great Script, just a few quick questions. I have a datagrid which i am trying to loop through client side, and i want to click on a button which kicks off the first row in the datagrid, and then use the RS.Execute command to run the code behind, then recursively call the same RS.Execute again, it doesn't work. It goes through the initial javascript... runs the RS.Execute the first time. The callback runs and updates the result to the correct column, but when it goes to run the RS.Execute it stops, the page doesn't error but it just stops.
Call Back...
function updateComments(result,rowid)
{
var myTable = document.getElementById("Main1_DCHMain__ctl0_dgBOMData");
var myRows = myTable.getElementsByTagName("tr");
var curRowColumns = null;
curRowColumns = myRows[rowid].getElementsByTagName("td");
curRowColumns[5].getElementsByTagName("span")[0].innerHTML = result;
rowid++;
curRowColumns = null;
curRowColumns = myRows[rowid].getElementsByTagName("td");
alert(curRowColumns[0].getElementsByTagName("span")[0].innerHTML);
alert(curRowColumns[4].getElementsByTagName("input")[0].value);
alert(rowid);
//All alert boxes show the correct data, which is the updated information from Row 2
RS.Execute("validateOrderInfo.aspx", "TestJava", curRowColumns[0].getElementsByTagName("span")[0].innerHTML, curRowColumns[4].getElementsByTagName("input")[0].value, updateCommentsTwo, rowid);
}
Initial javascript call...
function LoopThroughOrders()
{
var myTable = document.getElementById("Main1_DCHMain__ctl0_dgBOMData");
var myRows = myTable.getElementsByTagName("tr");
var curRowColumns = null;
var i = null;
i = 1;
var dataForRow = "";
curRowColumns = myRows[1].getElementsByTagName("td");
RS.Execute("validateOrderInfo.aspx", "TestJava", curRowColumns[0].getElementsByTagName("span")[0].innerHTML, curRowColumns[4].getElementsByTagName("input")[0].value, updateComments, i);
}
|
|
|
|
|
|
Sorry http://workspaces.gotdotnet.com/JSRS[^] but there hasn't been much activity around it in a long time.
FWIW - The big problem with this type of scripting solution is browser support limitations, DHTML and Layers. I spoke with Brent about a resurrection in 2003 but he felt that it was not warranted and JSRS had reached the end of it's abilities. Since most ASP.Net works around postback methodologies and extensive IE caching capabilities most remote scripting requirements have died. Im not sure but I heard today that the next version of IE will be fully W3C compliant.
|
|
|
|
|
Hi, I've got this problem: I'm catching the onclick event for a button and then call the remote scripting to do something (in my case edit a treeview), the problem I have is that some how the event never end. I click the button, catch the event, do what I need to do whit the remote scripting call an then when I click again in some place, make te same thing!
Excuse my english
Thanks
Martín
|
|
|
|
|
Hi Martin,
I'm not understanding your problem or how to go about reproducing it. Please explain it in more detail.
Thanks,
Alvaro
Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is. -- GWB, 1999.
|
|
|
|
|
I want to edit my tree, so I put this code in the aspx to catch the event and make the RS Call:
<script event="onclick" for="btnSubmitNodo"><br />
RS.Execute("estructura.aspx", "UpdatePais", txtInputNode, addToNode);<br />
</script><br />
The method "UpdatePais" which is in the code behind return a string whith the parameters I need to fill the new treenode, the callback AddToNode recive this parameters and insert in the tree the new treenode. All of this works ok, but the problem is than when O try to click in some place of my aplication, the event onclick is called again and again .... why? It seems that the event never end so very time I click is executed again. For the moment I resolve this problem sending an alert when the callback end, but I dont want to send an alert every time I edit the tree.
Can you help me! I hope you find understood to me!
Thenks!
Martín Llanos
|
|
|
|
|
Good implementation.
Another technique for doing this that is increasingly popular (see http://maps.google.com and others) is called AJAX which stands for Asynchronous JavaScript and XML.
Instead of a hidden IFRAME, an XmlHttpRequest object that is directly supported by most modern browsers (including Mozilla variants) makes the HTTP call to retrieve data (often, but not always XML) and client-side JavaScript then alters the page contents based on the returned values.
There is a company called "Dart" that has taken this concept and integrated it into ASP.Net and Visual Studio as a set of 20-some controls that raise and respond to server-side events/code without posting the page back (refreshing the page). Check it out here: Live Controls[^]
Extremely powerful, all client-side code is taken care of for you, and the programming model remains unchanged. Your existing server-side code (in the codebehind file) responds to the events.
I don't work for them or anything, but found their product compelling and a huge timesaver when creating these kinds of advanced UI's.
|
|
|
|
|
Thanks for the info. Cool stuff!
Regards,
Alvaro
Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is. -- GWB, 1999.
|
|
|
|
|
hi..
Thanks a lott,code works great,but the values are lost on post to server,ie i'm having 3 dropdown list an all work great without post.but whenever i click button all the dropdowns are refreshed...y?can u help me.??its very urgent
Thanks in advance
regards
asha
|
|
|
|
|
Hi Asha,
You need to reload the dropdowns when you post to the server. The demo shows this. Inside Page_Load I only load the type when IsPostBack is false but the amount is loaded every time. That's why I also disabled the ViewState for it.
Regards,
Alvaro
Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is. -- GWB, 1999.
|
|
|
|
|
Dear Mr. Alvaro Mendez
I thank you for your great job. Your codes are so great!
Now I'm testing the screen with 5 dropdownlists which use your remote scripting.
It works good. However, After selections of lists, if I click the button to submit, All selected values except data-bound one, are cleared.
I've tested it in debug mode. but there's no items of lists in the server when it is submitted, nevertheless it has items in the browser.
How can I make them retain their contained items and selected values?
What does the demo mean? which demo?
Could you make it more clear?
Regards,
Jay.
stupid developer....
|
|
|
|
|
kupi93 wrote:
What does the demo mean? which demo?
I'm referring to the demo files (rsDemo.aspx, rsDemo.xml) that are part of the download. That page has a Submit button and shows how to address your problem.
Regards,
Alvaro
Explain to the mothers & fathers of American servicemen that may come home in body bags why their son or daughter have to give up their life?" -- Sean Hannity, 1999.
|
|
|
|
|
Hi~~
I have solved it in another stupid manner with javascript and hidden textbox contols.
Now I'll expain to you my solution.
In brief, I made my page post back the option values and selected value to the server.
And the server re-generates the postbacked options and sets selected value in pre-render method.
In user's eyes, the page is just refreshed, but in every rendering, the page has diferrent
options in a html source level.
first of all, I made the hidden textbox server-controls in my page as follows.
. // In *.aspx file...
.
.
<div style="DISPLAY: none; VISIBILITY: hidden">
<asp:textbox id="txtWCValue" runat="server" Width="72px"></asp:textbox>
<asp:textbox id="txtWCSelect" runat="server" Width="72px"></asp:textbox>
</div>
.
.
And I've made the javascript functions as follows.
. // In *.aspx file...
.
.
<script language="JavaScript">
function OnSelectedChange( strID )
{
var ddlS = document.getElementById( strID );
var strValue = ddlS.value;
if ( strID == 'ddlArea' )
{
window.status = 'Loading...';
RS.Execute( '../InquiryCondition.aspx', 'GetWCenterALL', strValue, UpdateWC );
}
else if ( strID == 'ddlWCenter' )
{
SaveSelect( strID, 'txtWCSelect' );
}
}
function UpdateWC( result )
{
RS.ReplaceOptions( document.getElementById( 'ddlWCenter' ), result );
document.getElementById( 'txtWCValue' ).value = result;
OnSelectedChange( 'ddlWCenter' );
window.status = "";
}
function SaveSelect( strDDL, strTextBox )
{
var ddlS = document.getElementById( strDDL );
var txtSelect = document.getElementById( strTextBox );
txtSelect.value = ddlS.options[ ddlS.selectedIndex ].value;
window.status = "";
}
function OnLoad()
{
OnSelectedChange( 'ddlArea' );
}
</script>
<script language="C#" runat="server">
/***********************************************************************
* Objective : method to set the attribute of body tag. It changes the
* event of "Onload" in body tag in according to the state of
* page(Initial request or postbacked)
* Param : object Source - event sender, not used
* EventArgs e - event argument, not used
* Return : void
***********************************************************************/
void Loading(object Source, EventArgs e)
{
if( !this.IsPostBack )
DailyProdByWC.Attributes["onload"] = "javascript:OnLoad();";
else
DailyProdByWC.Attributes["onload"] = "";
}
</script>
.
.
<BODY id="DailyProdByWC" text="#000000" bgColor="#eae9dc" leftMargin="0" topMargin="0" onload="Loading" rightMargin="0" runat="server">
.
.
< When the user load the page fist time, he/she needs to see default option values.
In body tag, C# script changes event handler of onload event in body tag with the state
of page.
( When the page is loaded first, it performs "OnLoad()" function of javascript. So he/she can
see default option values filled by remote script. when it's postbacked, c# script function
change its onload envent handler like this[ onload="" ] and doesn;t anything. So it can
retain its previous selected value. ) >
And every DropdownList control has its "OnChange" event handler as follows.
. // in codebehind of my page
.
.
private void DailyProdByWC_PreRender(object sender, System.EventArgs e)
{
this.ddlArea.Attributes.Add( "OnClick", "javascript:OnSelectedChange('ddlArea');" );
this.ddlWCenter.Attributes.Add( "OnClick", "javascript:OnSelectedChange('ddlWCenter');" );
.
.
.
When the user selects dropdownlist, "OnChange" event occurs and it calls its remote script fuction in "InquiryCondition.aspx.cs" as follows.
. // In "InquiryCondition.aspx.cs"
.
.
/***********************************************************************
* Objective : method to return the conditions of work centers
* Param : String strArea - Area ID
* Return : String - html values of conditions
***********************************************************************/
public String GetWCenterALL( String strArea )
{
DataSet ds = Session[ "INQUIRY_CONDITION" ] as DataSet;
if ( ds == null || ds.Tables.IndexOf( "SYS_WC" ) == -1 )
return "<option value=''>-- MES Error! --</option>";
StringBuilder result = new StringBuilder();
DataRow[] drs = ds.Tables[ "SYS_WC" ].Select( "AREA_ID='" + strArea + "'" );
if ( drs.Length > 1 )
result.Append( "<option value='-1'>ALL</option>" );
else
{
ds.Dispose();
return "<option value='-1'>-- Not Available --</option>";
}
foreach (DataRow dr in drs )
{
result.Append("<option value='" + dr[ "WC_ID" ] + "'>" + dr[ "WC" ] +
" : " + dr[ "WC_NAME" ] + "</option>");
}
return result.ToString();
}
.
.
.
"GetWCenterALL( String strArea )" method returns html options values to the user's browser.
And javascript function, "UpdateWC( result )" fills options and saves them in the dedicated
textbox( "txtWCValue" ). And when the dropdownlist filled by remotescript changes its selection,
its selected value is saved in the dedicated textbox( "txtWCSelect" ).
So options filled by remotescript and user's selection can be post-backed.
finally, the code-behind fills these post-backed values into to its original dropdownlist as follows.
. // in code-behind of my page.
.
.
private void DailyProdByWC_PreRender(object sender, System.EventArgs e)
{
this.ddlArea.Attributes.Add( "OnClick", "javascript:OnSelectedChange('ddlArea');" );
this.ddlWCenter.Attributes.Add( "OnClick", "javascript:OnSelectedChange('ddlWCenter');" );
.
.
.
.
this.SetDropDownList( this.ddlWCenter, this.txtWCValue.Text, this.txtWCSelect.Text );
}
/***********************************************************************
* Objective : method to set the options of dropdownlists with the post
* -backed option data.
* Param : DropDownList ddlSelect - Dropdownlist object to be set
* string strOptions - option strings
* string strSelect - selected value string
* Return : void
***********************************************************************/
private void SetDropDownList( DropDownList ddlSelect, string strOptions, string strSelect )
{
if( strOptions != "" )
{
ddlSelect.Items.Clear();
char[] chrdelim1 = {'<','>'};
char[] chrdelim2 = {'\''};
string[] strSect1 = strOptions.Split( chrdelim1 );
for( int i = 1 ; i < strSect1.Length ; i= i + 4)
{
string strValue = strSect1[ i ].Split( chrdelim2 )[ 1 ];
ddlSelect.Items.Add( new System.Web.UI.WebControls.ListItem( strSect1[ i+1 ], strValue ) );
}
if ( strSelect != "" )
ddlSelect.SelectedValue = strSelect;
}
}
Therefore, the code-behind can fills its values fiiled by remotescript. And the page can retain
its options and selected value.
In user's eyes, it's just refreshed!.
What a stupid manner it is!!!
p.s. I'm not good at writing and speaking english...
I know you'll understand...
If you know more better solution, let me know please.
I hate this method.
Jay
stupid developer....
|
|
|
|
|
hi..
can u plz make it little more clear?ie the situvation is i'm having 4 dropdown.make,segment,subsegmnet,product.On selecting make,values of corresponing make is to be filled in segement,on selecting a segment subsegment should fill with corresponding segment.. like wise up to product.On selecting Product i have to fill some textbox with values corresponding to tat product.some code in selected index change of product drop down.but the problem is that when i select a product all the other 3 dropdowns will loss the selected value...y???i think u got my problem...can u help me...?
thanking u
asha
|
|
|
|
|
Hello, I tried your component and I find it works fine, except the fact that, when saving back texts in non english languages, all special characters, like german umlauts, disappear.
I rewmember having had that problem long time ago in asp,but I don't remember how I solved that.
Do you have a hint ?
|
|
|
|
|
Hi,
the problem is due to a bug in rs.js. I had the same issue with french accents (eh eh those stranges languages...) and fixed it.
I emailed you the fixed version, normally you should already have received it. the problem is when using a GET method, the way of escaping those special characters is not done by the 'escape' function (like in the original code) but should be done by 'encodeURIcomponent' function.
Note also that you should be careful to try using POST method instead of the GET method cause it's more efficient (position RS.usePOST = true before using the RS object).
Have fun.
Regards.
Chic
|
|
|
|
|
thanks, it works ok for european characters - but unfortunately not for east asian characters, with which I am having to deal.
When I try to transmit strings containing thai or chinese characters, I get an error:
while invoking the remote method - input string was not in correct format
Maybe the author knows a solution ?
|
|
|
|
|
sorry, I was wrong - everything works perfect now, even with east asian characters. I don't know what happended before and finally I don't want to know....
UH
|
|
|
|
|
Why the page refresh when i do Remote scripting?
|
|
|
|
|
The page refresh when you click the submit button, but when you change the select make a Remote Scripting to fill the other
|
|
|
|
|
The page does not really refresh. What refreshes is hidden IFRAME element in the page which does a postback to the page with with the remote method. Unfortunately this cause the status bar to behave as if the whole page was refreshing when only the IFRAME is doing so.
Regards,
Alvaro
Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is. -- GWB, 1999.
|
|
|
|
|
Hi,
I use your remotescripting blog. But sametime i receive this error message :
"'options' is null or not an object".
When i use script debugger, application stoped in rs.js, while rows.
RemoteScripting.prototype.ReplaceOptions = function(element, optionsHTML)
{
// Remove any existing options
while (element.options.length > 0)
element.options[0] = null;
In this state, element and options is null
have u ever received this message ??
Thanks
Mehmet
|
|
|
|
|
Hi Mehmet,
Make sure when you call ReplaceOptions that element is a valid object of type select . In other words, it must refer to an existing dropdown list in your form, otherwise you'll receive the error.
Regards,
Alvaro
Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is. -- GWB, 1999.
|
|
|
|
|
I have this exception:
Message "No se puede encontrar el miembro."
StackTrace " at System.DefaultBinder.BindToMethod(BindingFlags bindingAttr, MethodBase[] match, Object[]& args, ParameterModifier[] modifiers, CultureInfo cultureInfo, String[] names, Object& state)\r\n at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters)\r\n at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)\r\n at AMS.Web.RemoteScriptingClient.InvokeMethod() in c:\\documents and settings\\mllanos\\escritorio\\remotescriptingsourceandbinaries\\remotescripting\\remotescripting.cs:line 265"
Is this a bug? Thank you!
PD: Do you speak spanish???
Martín
|
|
|
|
|