一千萬個為什麽

搜索

關於asp.net事件處理的問題

有什麽區別



和is the attribute AutoPostBack="True" always required?

Iam問,因為似乎我的OnSelectedIndexChanged事件似乎總是被調用兩次(編輯:當我使用SelectedIndexChanged時,根本不調用處理程序)。

Why could this be?

編輯: 這些在我從得到兩次射擊的事件中獲得的堆棧跟蹤。後者似乎是從某種計時器調用的。我從來沒有創造過一個時間,它必須是一些系統。

   MyApp!MyNamespace.ListenControl.AuswahlGeändert(object sender = {System.Web.UI.WebControls.DropDownList}, System.EventArgs e = {System.EventArgs}) Zeile 44  C#
    System.Web.dll!System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(System.EventArgs e = {System.EventArgs}) + 0x70 Bytes   
    System.Web.dll!System.Web.UI.WebControls.DropDownList.RaisePostDataChangedEvent() + 0x87 Bytes  
    System.Web.dll!System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() + 0xb Bytes    
    System.Web.dll!System.Web.UI.Page.RaiseChangedEvents() + 0xa6 Bytes 
    System.Web.dll!System.Web.UI.Page.ProcessRequestMain(bool includeStagesBeforeAsyncPoint = true, bool includeStagesAfterAsyncPoint = true) + 0x5ce Bytes 
    System.Web.dll!System.Web.UI.Page.ProcessRequest(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint = true) + 0x84 Bytes 
    System.Web.dll!System.Web.UI.Page.ProcessRequest() + 0x51 Bytes 
    System.Web.dll!System.Web.UI.Page.ProcessRequestWithNoAssert(System.Web.HttpContext context) + 0x16 Bytes   
    System.Web.dll!System.Web.UI.Page.ProcessRequest(System.Web.HttpContext context) + 0x32 Bytes   
    App_Web_bm-nkhnz.dll!ASP.kfzpage_aspx.ProcessRequest(System.Web.HttpContext context = {System.Web.HttpContext}) + 0x26 Bytes    C#
    System.Web.dll!System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() + 0xb6 Bytes 
    System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step = {System.Web.HttpApplication.CallHandlerExecutionStep}, ref bool completedSynchronously = true) + 0x4c Bytes  
    System.Web.dll!System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(System.Exception error) + 0x133 Bytes  

    System.Web.dll!System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext context, System.AsyncCallback cb, object extraData) + 0x7c Bytes  
    System.Web.dll!System.Web.HttpRuntime.ProcessRequestInternal(System.Web.HttpWorkerRequest wr = {Microsoft.VisualStudio.WebHost.Request}) + 0x17c Bytes  
    System.Web.dll!System.Web.HttpRuntime.ProcessRequestNoDemand(System.Web.HttpWorkerRequest wr) + 0x63 Bytes  
    System.Web.dll!System.Web.HttpRuntime.ProcessRequest(System.Web.HttpWorkerRequest wr) + 0x47 Bytes  
    WebDev.WebHost.dll!Microsoft.VisualStudio.WebHost.Request.Process() + 0x165 Bytes   
    WebDev.WebHost.dll!Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Microsoft.VisualStudio.WebHost.Connection conn = {System.Runtime.Remoting.Proxies.__TransparentProxy}) + 0x6c Bytes   
    [Anwendungsdomänenübergang] 
    WebDev.WebHost.dll!Microsoft.VisualStudio.WebHost.Server.OnSocketAccept(object acceptedSocket) + 0x7d Bytes 
    mscorlib.dll!System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(object state) + 0x2f Bytes   
    mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x6f Bytes    
    mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(System.Threading._ThreadPoolWaitCallback tpWaitCallBack) + 0x53 Bytes 
    mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(object state) + 0x59 Bytes    

這是第二次調用事件時:

MyApp!MyNamespace.ListenControl.AuswahlGeändert(object sender = {System.Web.UI.WebControls.DropDownList}, System.EventArgs e = {System.EventArgs}) Zeile 44 C#
        System.Web.dll!System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(System.EventArgs e = {System.EventArgs}) + 0x70 Bytes   
        System.Web.dll!System.Web.UI.WebControls.DropDownList.RaisePostDataChangedEvent() + 0x87 Bytes  
        System.Web.dll!System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() + 0xb Bytes    
        System.Web.dll!System.Web.UI.Page.RaiseChangedEvents() + 0xa6 Bytes 
        System.Web.dll!System.Web.UI.Page.ProcessRequestMain(bool includeStagesBeforeAsyncPoint = true, bool includeStagesAfterAsyncPoint = true) + 0x5ce Bytes 
        System.Web.dll!System.Web.UI.Page.ProcessRequest(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint = true) + 0x84 Bytes 
        System.Web.dll!System.Web.UI.Page.ProcessRequest() + 0x51 Bytes 
        System.Web.dll!System.Web.UI.Page.ProcessRequestWithNoAssert(System.Web.HttpContext context) + 0x16 Bytes   
        System.Web.dll!System.Web.UI.Page.ProcessRequest(System.Web.HttpContext context) + 0x32 Bytes   
        App_Web_bm-nkhnz.dll!ASP.kfzpage_aspx.ProcessRequest(System.Web.HttpContext context = {System.Web.HttpContext}) + 0x26 Bytes    C#
        System.Web.dll!System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() + 0xb6 Bytes 
        System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step = {System.Web.HttpApplication.CallHandlerExecutionStep}, ref bool completedSynchronously = true) + 0x4c Bytes  
        System.Web.dll!System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(System.Exception error) + 0x133 Bytes  

        System.Web.dll!System.Web.HttpApplication.ResumeStepsFromThreadPoolThread(System.Exception error) + 0x25 Bytes  
        System.Web.dll!System.Web.HttpApplication.AsyncEventExecutionStep.ResumeStepsWithAssert(System.Exception error) + 0x28 Bytes    
        System.Web.dll!System.Web.HttpApplication.AsyncEventExecutionStep.OnAsyncEventCompletion(System.IAsyncResult ar) + 0x84 Bytes   
        System.Web.dll!System.Web.HttpAsyncResult.Complete(bool synchronous, object result, System.Exception error, System.Web.RequestNotificationStatus status) + 0x3e Bytes   
        System.Web.dll!System.Web.SessionState.SessionStateModule.PollLockedSessionCallback(object state) + 0x169 Bytes 
        mscorlib.dll!System.Threading._TimerCallback.TimerCallback_Context(object state) + 0x2f Bytes   
        mscorlib.dll!System.Threading.ExecutionContext.runTryCode(object userData) + 0x51 Bytes 
        [Übergang von Systemeigen zu Verwaltet] 
        [Übergang von Verwaltet zu Systemeigen] 
        mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x67 Bytes    
        mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x45 Bytes    
        mscorlib.dll!System.Threading._TimerCallback.PerformTimerCallback(object state) + 0x6b Bytes    
        [Anwendungsdomänenübergang] 

最佳答案

[asp:DropDownList 1]和[asp:DropDownList 2]有什麽區別?

SelectedIndexChanged is not a valid attribute for an asp:DropDownList tag, so ASP.NET won't do anything with it.

我在問,因為它似乎是我的   OnSelectedIndexChanged-event似乎   總是被叫兩次......為什麽   這可能是嗎?

堆棧跟蹤表明第二個事件調用是由重入線程引起的。您是從頁面運行任何異步委托,使用客戶端回調還是使用第三方控件?

轉載註明原文: 關於asp.net事件處理的問題