简体   繁体   中英

Passing parameter to the method of an aspx page from Javascript

Code I tried:

Page1.aspx:

id value is 2

location.href = "Page2.aspx/Method1";

Page2.aspx:

public void Method1(string id)
{
}

I want to pass the parameter value - id which is 2 to the Method1 in Page2.aspx from Page1.aspx using Javascript .

Assuming that Method1 is declared in codebehind as below: ( more info )

[WebMethod]
public static void Method1(string id)
{
}

Have you tried this code?

location.href = "Page2.aspx/Method1?id=2";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM