C# 从JavaScript调用可能返回另一个JavaScript函数的代码隐藏函数
我有一个问题,这个工作的一个按钮,而不是另一个按钮 一个有效的是一个按钮,它调用一个modalpoup向UpdatePanel内的GridView添加一个新行。如果成功,它会弹出一个带有消息的警报,否则会弹出另一个带有异常消息的警报。该代码与其他代码非常相似,只是它位于ModalPopupXtender中 引发有关EventValidation的已知异常的按钮如下所示: 网站: 那么为什么会发生这种情况呢?为什么这次不行 编辑:现在我检查了一下,ModalPopup中的working按钮更改的标签被包装在UpdatePanel中。我不知道这是否重要,但请注意C# 从JavaScript调用可能返回另一个JavaScript函数的代码隐藏函数,c#,javascript,asp.net,gridview,updatepanel,C#,Javascript,Asp.net,Gridview,Updatepanel,我有一个问题,这个工作的一个按钮,而不是另一个按钮 一个有效的是一个按钮,它调用一个modalpoup向UpdatePanel内的GridView添加一个新行。如果成功,它会弹出一个带有消息的警报,否则会弹出另一个带有异常消息的警报。该代码与其他代码非常相似,只是它位于ModalPopupXtender中 引发有关EventValidation的已知异常的按钮如下所示: 网站: 那么为什么会发生这种情况呢?为什么这次不行 编辑:现在我检查了一下,ModalPopup中的working按钮更改的标
EDIT2:该页也可以在母版页中工作。不知道它是否有用。我尝试过用UpdatePanels和AsyncPostBackTrigger包装编辑按钮和GridView,但仍然得到了相同的异常。好的,对于那些对此感兴趣的人来说,问题在于_doPostBack调用。由于我传递的参数_EVENTARGUMENT是动态的,因此我无法通过RegisterForEventValidation方法注册这些事件,因为它要求两个常量字符串:控件的UniqueID和它将随它一起传递的参数 因此,我停止向doPostBack传递参数,而不是按钮的UniqueID,并通过其他媒体cheifly将我感兴趣的变量、隐藏字段值传递给Page类中的全局变量 这就解决了问题,使程序按预期运行。我将按钮包装在与GridView相同的更新面板中,以避免在不刷新的情况下生成自动回发和更改网格的值 如果有人对代码感兴趣,我可以提供
OnClientClick="Click_Alquilar(); return false"
instead of this use
OnClientClick="return Click_Alquilar();
and in javascript
use return false;
in functions like
function Click_Alquilar() {
if (index == '') {
alert("Debe elegir una película para alquilar");
return false;
}
else {
if (confirm("¿Quiere alquilar la película '" + selected.childNodes[2].innerText + "'?")) {
__doPostBack('<%= btnAlquilar.UniqueID %>', index);
}
}
}
function Click_Alquilar() {
if (index == '') {
alert("Debe elegir una película para alquilar");
}
else {
if (confirm("¿Quiere alquilar la película '" + selected.childNodes[2].innerText + "'?")) {
__doPostBack('<%= btnAlquilar.UniqueID %>', index);
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{...}
else
{
ProcessAjaxPostBack(sender, e);
}
}
private void ProcessAjaxPostBack(object sender, EventArgs e)
{
if ((Request.Params["__EVENTTARGET"] != null) && (Request.Params["__EVENTARGUMENT"] != null))
{
...
if (Request.Params["__EVENTTARGET"] == this.btnAlquilar.UniqueID)
{
index = Convert.ToInt32(Request.Params.Get("__EVENTARGUMENT").TrimStart('r', 'o', 'w'));
btnAlquilar_Click(Request.Params.Get("__EVENTARGUMENT"));
}
}
}
protected void btnAlquilar_Click(string id)
{
string message = "";
if (BAC.BAC.CheckUserAge(lblUserId.Text) < Convert.ToInt32(dgvPeliculas.Rows[index].Cells[7].Text))
{
btnBorrar.Visible = false;
btnEditar.Visible = false;
btnNuevo.Visible = false;
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('No tiene la edad mínima para alquilar la película.')", true);
}
else
{
try
{
BAC.BAC.NewAlquiler(lblUserId.Text, dgvPeliculas.Rows[index].Cells[0].Text, dgvPeliculas.Rows[index].Cells[9].Text);
}
catch (Exception ex)
{
message = Change_ExceptionMessage(ex.Message);
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('No se pudo alquilar la película: " + message + "')", true);
}
}
}
protected override void Render(HtmlTextWriter writer)
{
this.Page.ClientScript.RegisterForEventValidation(btnAlquilar.UniqueID);
base.Render(writer);
}
OnClientClick="Click_Alquilar(); return false"
instead of this use
OnClientClick="return Click_Alquilar();
and in javascript
use return false;
in functions like
function Click_Alquilar() {
if (index == '') {
alert("Debe elegir una película para alquilar");
return false;
}
else {
if (confirm("¿Quiere alquilar la película '" + selected.childNodes[2].innerText + "'?")) {
__doPostBack('<%= btnAlquilar.UniqueID %>', index);
}
}
}