Reputation: 982
I have a website that contains a gridview. I have placed a linkbutton at the end of the gridview, when pressed it calls an API and updates my SQL table with the data from the API call. It performs the response.write and appears to refresh the page, but the updates don't show up once it's finished. I have to go forward 1 page and back to the original page for the updates to show up. How can I achieve this?
I have tried using gridview.Save() after the responose.write. Also tried Response.Redirect(Request.RawUrl); but it refreshes to pageindex 1.
try {
connect.Open();
UpdateExistingNote.ExecuteNonQuery();
Response.Write("Message to user");
GridView.Save();
}
Upvotes: 0
Views: 121
Reputation: 1066
As requested by the OP, here is how i handled the textbox refresh:
Dynamically create textbox:
TextBox tb = new TextBox();
tb.ID = "tbNewExpireDate";
tb.Text = dt.Rows[j][k].ToString();
tb.TextMode = TextBoxMode.Date;
tb.EnableViewState = false;
hdOldExpireDate.Value = dt.Rows[j][k].ToString();
Button btn = new Button();
btn.OnClientClick += "return VerifyExpireDateSave()";
btn.Click += btnSaveExpireDate_Click;
btn.Text = "Save";
Panel pnl1 = new Panel();
pnl1.ID = "pnlExpiration";
pnl1.Controls.Add(tb);
pnl1.Controls.Add(btn);
Then add panel to a control.
Javascript to remove the element:
function VerifyExpireDateSave() {
var answer = confirm("Are you sure you want to update this product key expiration date?");
document.getElementById('hdNewExpireDate').value = document.getElementById('tbNewExpireDate').value;
var pnl = document.getElementById('pnlExpiration');
var tb = document.getElementById('tbNewExpireDate');
pnl.removeChild(tb);
return answer;
}
All controls are created in post back so once the javascript function returns true, the post back happens after removing the child element from the panel. This made it so after the post back, the new value was in the textbox. Also, this textbox happened to be a date textbox and the functionality in my program was to update the expiration date of a product key. And the problem i was having was that the old date was showing on reload. The script is what made the correct date show after post back.
Upvotes: 1