我陷入了这个错误。。。
<a id="25" class="abc" href="example.aspx" onclick="return myfunction(this);">
我的函数代码获取该链接的id并将其保存到会话变量中。。
function myfunction(a)
{
var myid = a.id;
'<%Session["x"] ="' + myid +'";%>';
return;
}
因此,在此之后,它将重定向example.aspx,并将example.aspx.cs文件的代码转换为:
static int j = 0;
if(Session["x"]!=null)
{
j = int.Parse(Session["x"].ToString());
}
此换行错误:FormatException:输入字符串的格式不正确。。
堆栈:
[FormatException: Format of input string is not correct..]
System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7476983
System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119
System.Int32.Parse(String s) +23
example.Page_Load(Object sender, EventArgs e) in example.aspx.cs:103
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
代码中的问题本质上是,当服务器(即.cs)向客户端(即.html、.js)发送数据时,仅使用'<% ... %>'
。
要将数据从客户端传递到服务器,您需要使用其他替代方法,如Query Strings或html <form>
标记。