回调阻止回发 [英] Callback prevents Postback

查看:103
本文介绍了回调阻止回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在使用vs2008,并创建了一个回调,如MSDN所描述的asp.net页面,代码在c#后面.
它工作正常,但只有一次.在第二个回调没有任何反应,我无法重定向到另一个页面或导致回调.所有客户端javascript都能完美运行.
我在运行页面时没有任何错误.
需要帮助.

代码:

hi all,
i''m using vs2008 and created a callback as described at MSDN for asp.net page, code behind c#.
it works fine but only once. on the second callback nothing happens and i cannot redirect to another page or cause callback. all clientside javascript works perfectly.
i don''t get any errors running the page.
help needed.

code:

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts

  public partial class Letter : System.Web.UI.Page, ICallbackEventHandler
  {

      public void RaiseCallbackEvent(String eventArgument)
      { 
          ctrlString = eventArgument;
          SaveLetter();

          returnValue = LetterCreation_Click(); //LetterCreation_Click() returns a string!
      }
      public string GetCallbackResult()
      {
          return returnValue;
      }


    protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack)
      {
          ClientScriptManager cm = Page.ClientScript;
          String cbReference = cm.GetCallbackEventReference       (this, "arg", "ReceiveServerData", "context", "ReceiveServerError", false);
          String callbackScript = "function CallServer(arg, context) {" + cbReference + "; }";
          cm.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
      }



客户端:



client side:

function ReceiveServerData(Result, context)
        {
           document.getElementById('FinalText').value = Result;
        }
        function ReceiveServerError(Error)
        {
            alert(Error);
        }


调用回调:


calling the callback:

CallServer(document.getElementById('ControlArray').value,''); //element ControlArray is a string and not an array!

推荐答案



我的建议是从pageload事件中删除Ispostback条件.

只需编写该registercallback即可,而且不要写条件.

最好的
Hi,

my suggestion is remove Ispostback condition from pageload event.

And just write that registercallback .And don''t write in condition.

All the Best


这篇关于回调阻止回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆