从javascript调用非静态方法
嗨,我的功能是我需要上传一个xml文件,并在文件夹中检查该文件是否存在。 如果文件存在,我需要使用ok或cancel将文件替换为javascript中的弹出窗口,然后从按钮单击我需要保存xml文件并绑定到网格中。现在我可以保存文件,但我不能绑定到网格中。谢谢 我的文件上传代码从javascript调用非静态方法,javascript,asp.net,web-applications,non-static,Javascript,Asp.net,Web Applications,Non Static,嗨,我的功能是我需要上传一个xml文件,并在文件夹中检查该文件是否存在。 如果文件存在,我需要使用ok或cancel将文件替换为javascript中的弹出窗口,然后从按钮单击我需要保存xml文件并绑定到网格中。现在我可以保存文件,但我不能绑定到网格中。谢谢 我的文件上传代码 if (FileUpload1.HasFile){ if (FileUpload1.PostedFile.ContentType == "text/xml") { s
if (FileUpload1.HasFile){
if (FileUpload1.PostedFile.ContentType == "text/xml")
{
string filename = Path.GetFileName(FileUpload1.FileName);
string path = Server.MapPath(ConfigurationManager.AppSettings["Path"]) + filename;
if (File.Exists(path))
{
ScriptManager.RegisterStartupScript(this, GetType(), "", "ConfirmBox();", true);
ExistPath = path;
Session["FileUpload1"] = FileUpload1;
Session["GridView1"] = GridView1;
}
else
{
SaveXml(path);
}
}
}
Javascript
<script language="javascript" type="text/javascript">
function ConfirmBox() {
if (confirm("Do you want to overrite")) {
PageMethods.FileExist(document.getElementById('<%=hfConfirmValue.ClientID %>').value);
}
}
</script>
你肯定错过了一些非常重要的标签?像
asp.net
和诸如此类的?@T.J.Crowder,我知道我没有遗漏任何标记。它可以保存,但现在不显示在网格中。没有-没有-问题上的标记。底部的蓝色部分。标记相关技术(asp.net
,等等)。据我所知,您的页面在进行ajax调用后没有得到刷新,对吗?此FileExist函数是否正在调用?尝试使任何错误的按钮再次点击并绑定网格,并检查网格是否绑定?
[WebMethod(EnableSession = true)]
public static string FileExist(string confirm)
{
#region Save XML
string path = ExistPath;
FileUpload s = HttpContext.Current.Session["FileUpload1"] as FileUpload;
GridView g = HttpContext.Current.Session["GridView1"] as GridView;
s.SaveAs(path);
DataSet ds = new DataSet();
ds.ReadXml(Path.GetFullPath(path));
GlobalDS = ds;
g.DataSource = ds;
g.DataBind();
return "file updated";
#endregion
}