图像保存在AJAX JSON C#ASPNET中时自动关闭窗口浏览器
在我的图像保存在AJAX JSON C#ASPNET中时自动关闭窗口浏览器,c#,asp.net,json,ajax,gridview,C#,Asp.net,Json,Ajax,Gridview,在我的GridView中的C#ASP.NET 4中,我插入一个按钮来编辑在该模式下在浏览器上打开新网页的GridView行 protected void btn1_Click(object sender, EventArgs e) { ImageButton btn1 = (ImageButton)sender; GridViewRow row = (GridViewRow)btn.NamingContainer; int oID = Convert.ToInt32(gv
GridView
中的C#ASP.NET 4
中,我插入一个按钮来编辑在该模式下在浏览器上打开新网页的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);
}
<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');
},
failure: function (msg) {
alert(response.d);
},
error: function (msg) {
alert(response.d);
},
error: function (xhr, ajaxOptions, thrownError) {
alert("error : " + thrownError + JSON.stringify(image));
}
});
});
});
</script>
newpage.aspx
使用Ajax
和JSON
在此模式下在服务器上保存图像
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);
}
<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');
},
failure: function (msg) {
alert(response.d);
},
error: function (msg) {
alert(response.d);
},
error: function (xhr, ajaxOptions, thrownError) {
alert("error : " + thrownError + JSON.stringify(image));
}
});
});
});
</script>
有什么建议吗
谢谢您的帮助。这将取代服务器端按钮添加客户端按钮,从而完成此任务
<button type="button" onclick="closeme()">Close me</button>
<script>
function closeme() {
this.window.close();
}
</script>
关闭我
函数closeme(){
this.window.close();
}
这会有帮助