Cannot get the changed value ( aspx/jQuery/C# )
Alright this is the jQuery code I am using, followed by the C# code used to change the lastPoll value.
- $.ajaxSetup ( { cache: false } );
- var lastPoll = null;
- function Poll2() { $("#scripts").load("Ajax/ScriptToCheckTheFile.aspx", { projectId: $("#projectId").val(),
- lang: ($("#projectId").val().charAt(0) == "E") ? "eng" : "fra",
- lastPoll: lastPoll,
- projectName: $("#projectId option:selected").text() },
- function(result) {
-
- alert(lastPoll);
- } ); }
- MethodInfo WritableMethod;
- MethodInfo ReadOnlyMethod;
- BindingFlags Flags = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;
- WritableMethod = Request.Form.GetType().GetMethod( "MakeReadWrite" , Flags );
- ReadOnlyMethod = Request.Form.GetType().GetMethod( "MakeReadOnly" , Flags );
- FieldInfo FormField = Request.GetType().GetField( "_form" , Flags );
- WritableMethod.Invoke( Request.Form , null );
- Request.Form[ "lastPoll" ] = DateTime.Now.ToString();
- FormField.SetValue( Request , Request.Form );
- ReadOnlyMethod.Invoke( Request.Form , null );
The problem I am currently facing is that I cannot store the value from the c# code to the global var in my .js file containing the jQuery I provided.
If i had a simple "Request.Form[ "lastPoll" ];" right after my C# code, I would get the correct value, however, the alert in the jQuery will still be null. It seems like I am not affecting the global variable lastPoll but only the data name.
Is there a way to affect the var? Or any other way around this?