Click here to Skip to main content
15,888,162 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm losing many time trying to do a thing I dont know if Its possible:

C#
function botaoCarregarNotas() {
     PageMethods.verNum(verNum2);
     PageMethods.carregarNotas(verTexto);
 }
 // aqui é recebido o resultado
function verNum2(result) {
    var num = result;
    alert("num: "+num);
    return num;
 }
 // recebe texto
function verTexto(resultado){

var num = verNum2(paremeter);        // HERE IS THE PROBLEM
alert("num1: "+num);
 for(i=0; i< num; i++)
      loadNotes(resultado[i]);


Because I'm using AJAX I need to use this three functions, and I need to return num variable assigned at verNum2(), and use it at verTexto(). As I am using, its obviously wrong. - I get "num1: undefined", because I need to pass the parameter that I want to return.

How can I solve this problem ?
Posted
Updated 23-Dec-10 4:06am
v3

You are calling verNum2 without any parameters, like this:
var num = verNum2(); 


And because you called it without a parameter it has nothing to assign to num:
C#
function verNum2(result) {
    var num = result;
    alert("num: "+num);
    return num;
 }


Num is what you return and that is then unassigned because result was when calling it.

Good luck!
 
Share this answer
 
Comments
Maxdd 7 23-Dec-10 10:03am    
Yes I know, I guess I have to change the code on the server side :)
[no name] 23-Dec-10 10:26am    
If you know then why do you ask? Stop wasting our time.
Of course this doesn't work. Look at it.

verNum2 takes one parameter which assigns it to a local variable and then returns it. When you are calling it in verTextTo you are not giving a parameter, which means NULL will be returned.
 
Share this answer
 
Comments
Maxdd 7 23-Dec-10 10:08am    
I know Mark.

That's why I solved the problem at server side.

int num = Convert.ToInt32(verNum());
string[] texto = new string[num+1];

texto[0] = num.ToString();

int i;

for (i = 1; i <= num; )
{
while (dr.Read())
{
texto[i] = dr[0].ToString();
i++;
}

}

and then

var num = resultado[0];
alert("num1: "+num);

for(i=1; i<= num; i++)
loadNotes(resultado[i]);

I just guess that I was able to solve the problem at client side, but ok, no prob :)
[no name] 23-Dec-10 10:26am    
If you know then why do you ask? Stop wasting our time.
try this,

JavaScript
function botaoCarregarNotas_VerNum() 
{     
     PageMethods.verNum(verNum2);
}
function botaoCarregarNotas()
{
     PageMethods.carregarNotas(verTexto); 
} 
// aqui é recebido o resultado
function verNum2(result) 
{    
     var num = result;    
     alert("num: "+num);    
     return num; 
} 

// recebe texto
function verTexto(resultado)
{
      var num = botaoCarregarNotas_VerNum();        
      alert("num1: "+num); 
      for(i=0; i<num;>
          loadNotes(resultado[i]);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900