0

I have two ASP.Net functions in server side (code behind):

string GetError();
string GetErrorAtIndex(int, int);

In client side code, I use javascript to call the first function and it works fine

function test() {
    var x = <%= GetError() %>;
    alert('x');
}

However, am unable to call the second function which takes two parameters:

function test2() {
    var param1 = 10;
    var param2 = 100;
    var x = <%= GetErrorAtIndex(param1, param2) %>;
    alert('x');
}

I get the error

CS0103: The name 'param1' does not exist in the current context

I understand that this is because the javascript local variable won't have visibility in the ASP.Net call. I then thought of using HiddenFields to store/pass parameters, but am unable to do that.

Any hints/inputs would be appreciated.

Thanks!

2
  • 3
    I think that you don't understand the relationship between server and client. Commented Jan 10, 2014 at 16:30
  • 1
    @crush: Apart from your negative tone and no rather helpful information, I'd like to point that I have mentioned clearly that am looking for passing variables using hidden fields, without using a postback. Am sure even you don't understand that and that's why the trolling comment. Commented Jan 11, 2014 at 11:17

2 Answers 2

3

Because param1 is a JavaScript variable not an ASP.NET variable.

Sign up to request clarification or add additional context in comments.

1 Comment

If you read my question correctly, I already mentioned this as the last point. I fully understand that javascript vars won't have visibility in asp.net and vice versa. What I asked is of a 'way' to somehow pass this variable, without using AJAX PageMethods etc, like using ASP.Net hidden fields, which can be updated in javascript and ASP.net alike.
2

Look at the __doPostBack() method to send back Event Targets and arguments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.