Inside my .aspx I have some JSON code that looks like this:
function someFunctionName() {
var dataStuff = $.toJSON({
someData: $("#someData").text(),
someMoreData: $("#someMoreData").text()
});
$.ajax({
type: "POST",
url: "PageName.aspx/doIt",
data: dataStuff,
contentType: "application/json",
dataType: "json"
});
document.location.href = 'PageName.aspx';
}
Basically what I’m doing is pulling text from two labels on one page, and sending them to another page by calling the “doIt” function which looks like this:
<WebMethod()> _
Public Shared Sub doIt(ByVal someData As String, ByVal someMoreData As String)
MessageBox.Show("Successful execution!")
End Sub
Just so I’m clear, the “doIt” function and the JSON call are on two separate web forms. My problem is that with the “doIt” function being Shared, I can’t access any global variables of the class. And if I remove the Shared, my JSON doesn’t execute. Any solutions?
If it’s appropriate, you could change the fields in your class (the “global variables”, as you called them) to shared as well. Then they will be accessible from shared methods. However, that will mean their value will be shared among all instances of the class. If that’s what you want, though, that’s your answer.