In my GridView in C# ASP.NET 4 I insert a button to edit the row of GridView that open a new webpage on the browser in this mode
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);
}
The newpage.aspx use Ajax and JSON for save an image on the server and close window in this mode
<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>
Now i need refresh the Gridview after closing window
I have tried withous success these single solution, but the parent page with the GridView is not refreshed and the edited row is always available
window.opener.location.reload(true);
window.close();
Or
parent.location.reload(true);
window.close();
Or
location.href = 'gv.aspx' + qString;
window.close();
Or
window.location.replace("gv.aspx")
window.close();
Or
window.location = result.getResponseHeader('gv.aspx');
window.close();
Any suggestion?
Thanks for help.
code-behind
[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();
}
}
}