I write my project in Asp.net using JavaScript.My code is below:
<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";
}
This is my script tag.There are other functions too in script before this. As you look, I call my Save method in button's click.
<input type="button" class="button-style" style="width:50px; height:30px; margin-left:50%;" id="btnInsertOK" value="OK"/>
And my Save() method in code behind:
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;
}
When the project start running firstly, Save() runs, and it inserts default string.How can I fix this problem?