我有一个带有 HtmlInputHidden 字段的简单页面。我使用 Javascript 来更新该值,并且在回发页面时,我想读取该 HtmlInputHidden 字段的值。该 HtmlInputHidden 字段的 Value 属性在回发时是默认值(它在创建页面时具有的值,而不是通过 Javascript 反映的值)。我还尝试使用 ScriptManager.RegisterHiddenField(Page, "MyHtmlImputHiddenField", "initialvalue") 注册 HtmlInputHidden 字段,但它仍然只能让我读取“初始值”,即使我(通过 javascript)可以检查该值已更改。
我尝试对 rowid 进行硬编码,令我惊讶的是,在回发之后 gridview 与删除之前完全相同,但记录已从数据库中删除。(我已经调用了数据绑定方法)。
protected void gridViewDelete(object sender, GridViewDeleteEventArgs e)
{
bool bDelete = false;
bool bCheck = false;
if (hfControl.Value != "1")
{
// check relationship
bCheck = validation_method(.......);
if (bCheck)
{
bDelete = true;
}
}
else
{
hfControl.Value = "";
bDelete = true;
}
if (bDelete)
{
//process delete
}
else
{
string script = string.Empty;
script += " var x; ";
script += " x = confirm('are u sure?'); ";
script += " if (x){ " ;
script += " document.getElementById('hfControl').value = '1'; ";
script += " setTimeOut(__doPostBack('gridView','Delete$"
+ e.RowIndex + "'),0);";
script += " } ";
ScriptManager.RegisterClientScriptBlock(this,
Page.GetType()
, "confirm"
, script
,true);
}
}