如何解决将图像保存在AJAX JSON C#ASPNET
在C#ASP.NET 4的GridView中,我插入一个按钮来编辑GridView的行,以这种模式在浏览器上打开一个新网页
protected void btn1_Click(object sender,EventArgs e)
{
ImageButton btn1 = (ImageButton)sender;
GridViewRow row = (GridViewRow)btn.NamingContainer;
int oID = Convert.ToInt32(gv.DataKeys[row.RowIndex].Values[0]);
string queryString = "newpage.aspx?oID=" + oID.ToString();
string newWin = "window.open('" + queryString + "','_blank');";
ClientScript.RegisterStartupScript(this.GetType(),"pop",newWin,true);
}
newpage.aspx使用Ajax和JSON在服务器上保存图像并以这种模式关闭窗口
<script type="text/javascript">
$(function () {
$("#btnSave").click(function () {
var image = document.getElementById("cc").toDataURL("image/png");
image = image.replace('data:image/png;base64,','');
var qString = "?" + window.location.href.split("?")[1];
$.ajax({
type: 'POST',url: 'newpage.aspx/oImage' + qString,data: '{ "imageData" : "' + image + '" }',contentType: 'application/json; charset=utf-8',dataType: 'json',success: function (msg) {
alert('Ok');
window.close();
},failure: function (msg) {
alert(response.d);
},error: function (msg) {
alert(response.d);
},error: function (xhr,ajaxOptions,thrownError) {
alert("error : " + thrownError + JSON.stringify(image));
}
});
});
});
</script>
现在我需要在关闭窗口后刷新Gridview
我已经尝试过通过单个解决方案取得成功,但是带有GridView的父页面没有刷新,并且编辑后的行始终可用
window.opener.location.reload(true);
window.close();
或
parent.location.reload(true);
window.close();
或
location.href = 'gv.aspx' + qString;
window.close();
或
window.location.replace("gv.aspx")
window.close();
或
window.location = result.getResponseHeader('gv.aspx');
window.close();
有什么建议吗?
感谢帮助。
隐藏代码
[WebMethod()]
public static void oImage(string imageData)
{
string folderLocation = path + "\\" + DateTime.Now.ToString("ddMMyyyy") + "\\";
bool exists = Directory.Exists(folderLocation);
if (!exists)
{
Directory.CreateDirectory(folderLocation);
}
string fileNameWitPath = folderLocation +
Guid.NewGuid() + "_" + DateTime.Now.ToString("ddMMyyyyHHmmss") + ".png";
mtsp(fileNameWitPath);
using (FileStream fs = new FileStream(fileNameWitPath,FileMode.Create))
{
using (BinaryWriter bw = new BinaryWriter(fs))
{
byte[] data = Convert.FromBase64String(imageData);
bw.Write(data);
bw.Close();
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。