我使用JavaScript在Asp.net中编写我的项目。我的代码如下:
<script type="text/javascript">
. . .
var btnSaveInsert = document.getElementById("btnSaveInsert");
. . .
btnSaveInsert.onclick = function (e) {
e.preventDefault();
var s = <%=Save() %>;
modal2.style.display = "none";
modal3.style.display = "block";
}
这是我的脚本标签。在此之前,脚本中还有其他功能。 如您所见,我在按钮的单击中调用了Save方法。
<input type="button" class="button-style" style="width:50px; height:30px; margin-left:50%;" id="btnInsertOK" value="OK"/>
后面的代码中还有我的Save()方法:
protected string Save()
{
DataTable dt = new DataTable();
string json;
string active = Request.Form["txtActive"];
string code = Request.Form["txtCode"];
string name = Request.Form["txtName"];
string warehouse = Request.Form["txtWarehouse"];
string url = "http://InsertData?active=" + active + "&code=" + code + "&name=" + name + "&warehouse=" + warehouse + "";
using (WebClient client = new WebClient())
{
json = client.DownloadString(url);
}
string[] json1 = json.Split('>');
string[] json2 = json1[2].Split('<');
json = json2[0];
return json;
}
项目首先开始运行时,Save()运行,并插入默认字符串。如何解决此问题?