单击按钮或任何其他时,IsPostback始终为false

时间:2012-02-10 20:19:57

标签: asp.net vb.net postback ispostback

使用asp.net超过5年。但现在我面临着一个奇怪的问题。当我尝试从我创建的包含asp:button,asp:textbox等的表单发送电子邮件时,在代码页中它总是告诉IsPostBack错误。即使我点击发送邮件按钮(asp.net按钮)。我无法理解什么是问题。

回发的web.config文件中是否需要任何内容​​?

测试页http://buyerrs.com/Test.aspx

我确定它在测试页面中没有问题。因为这是非常正常的页面,只有一个按钮&代码在vb。在cache,urlrewrite或web.config中的某个地方出现问题。但我不明白在哪里?

    <?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

  <configSections>
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
          <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
          <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
          <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
        </sectionGroup>
      </sectionGroup>
    </sectionGroup>
  </configSections>

   <system.web>

     <httpHandlers>
       <remove verb="*" path="*.asmx"/>
       <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
       <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
       <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
     </httpHandlers>

      <httpModules>
        <add name="vchHttpModule" type="VchBaseSite.vchHttpModule" />
      </httpModules>

      <!-- need to increase the size of the permitted upload size -->
      <httpRuntime maxRequestLength="20480" />

      <!-- set compilation debug="false" for running application -->
      <compilation debug="true" strict="false" explicit="true" defaultLanguage="vb">
         <assemblies>
            <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
            <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
           <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
         </assemblies>
      </compilation>

      <trace enabled="false" pageOutput="true" localOnly="true" />

      <sessionState mode="Off" />

      <!-- customErrors mode="On|Off|RemoteOnly" -->
      <customErrors mode="Off">
         <error statusCode="404" redirect="404.aspx" />
         <error statusCode="500" redirect="500.html" />
      </customErrors>

      <pages enableViewState="false">
         <namespaces>
            <clear />
            <add namespace="System" />
            <add namespace="System.Collections" />
            <add namespace="System.Collections.Generic" />
            <add namespace="System.Configuration" />
            <add namespace="System.IO" />
            <add namespace="System.IO.Compression" />
            <add namespace="System.Linq" />
            <add namespace="System.Text" />
            <add namespace="System.Web" />
            <add namespace="System.Web.Security" />
            <add namespace="System.Web.UI.WebControls" />
            <add namespace="System.Web.UI" />
            <add namespace="System.Xml.Linq" />
         </namespaces>
         <controls>
           <add tagPrefix="vch" namespace="VchBaseSite" assembly="VchBaseSite" />
         </controls>
      </pages>

      <!-- set code access security trust level - this is generally set in the machine.config
      <trust level="Medium" originUrl=".*" />-->

      <machineKey
        validationKey="CF19275EF5E6206C1E289BAC5240240548B1015A2A68137B411A08E2F2BFE55223C42B1FECB10B6A660CD00DEE02F005959D7E4929660A81CF756E69BF3F56C8"
        decryptionKey="A32BD7AEDF208B05B85828E644774810C928F5F76A6AD0A50F982EBD235634A3"
        validation="SHA1" decryption="AES"
      />

      <authentication mode="None" />

      <roleManager>
          <providers>
              <clear />
          </providers>
      </roleManager>

   </system.web>

   <system.codedom>
      <compilers>
         <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <providerOption name="CompilerVersion" value="v3.5" />
            <providerOption name="WarnAsError" value="false" />
         </compiler>
         <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <providerOption name="CompilerVersion" value="v3.5" />
            <providerOption name="OptionInfer" value="true" />
            <providerOption name="WarnAsError" value="false" />
         </compiler>
      </compilers>
   </system.codedom>

   <!--
     The system.webServer section is required for running ASP.NET AJAX under Internet
     Information Services 7.0.  It is not necessary for previous version of IIS.
    -->
   <system.webServer>
      <validation validateIntegratedModeConfiguration="false" />


<!--
      <defaultDocument>
         <files>
            <clear />
            <add value="default.aspx" />

          <add value="Default.aspx" /> 
            <add value="default.htm" />
            <add value="Default.htm" />
         </files>
      </defaultDocument> -->
   </system.webServer>

   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" appliesTo="v2.0.50727">
         <dependentAssembly>
            <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" />
         </dependentAssembly>
         <dependentAssembly>
            <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" />
         </dependentAssembly>
      </assemblyBinding>

      <connectionStrings>
        <remove name="LocalSqlServer" />
      </connectionStrings>
   </runtime>

</configuration>

这是web.config文件

最后我发现错误上升。此网站代码基于此http://www.datafeedscripts.net/default.aspx软件。他们使用三个dll文件(vchsite.dll,vchLicense.dll,vchbasesite.dll)并在下面有一个httpmodule代码

<httpModules>
    <add name="vchHttpModule" type="VchBaseSite.vchHttpModule" />

当我排除那个dll并从web.config文件中删除httpmodule行后回工作正常。所以这是错误的。他们在Dll文件或httpmodule中做错了。

但仍然无法理解什么是错误。是否有机会从dll文件控制回发操作?

6 个答案:

答案 0 :(得分:2)

我知道这有点旧,但我会查看HttpModule。 vchHttpModule可能正在劫持请求并使InPostBack失效。

答案 1 :(得分:0)

您没有要处理的点击事件,而是将其作为提交按钮,而不会生成回发。

http://www.w3schools.com/aspnet/prop_webcontrol_button_usesubmitbehavior.asp

关闭提交行为。

答案 2 :(得分:0)

回发后查看您的页面来源,我看到了:

IsPostBack : False on 2/10/2012 3:50:06 PM

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
...

如何将“IsPostBack:False ..”模糊放在DOCTYPE之前。检查你的受保护的子Page_Load事件处理程序,并确保它是正确的语法等,因为它似乎可能在它应该之前触发,因此没有得到正确的IsPostBack状态。

答案 3 :(得分:0)

我不明白一个人的想法。你将AutoEventWireup设置为false,这意味着没有调用PageLoad,但是你说它被称为...有线...可能还有其他一些类被加载,这里有些混淆。

AutoEventWireup="false"

你可以把它变成真的看结果吗?

答案 4 :(得分:0)

尝试在Page标签中将AutoEventWireup设置为true。

答案 5 :(得分:0)

我看了一下IsPostBack MS实现,可以找到here also

通过反射,您可以“读取”那些if语句中使用的每个值。
不幸的是我使用C#,我希望你能把它翻译成VB

protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write(IsPostBack.ToString() + " " + DateTime.Now.ToShortDateString());
            Response.Write("<br />");

            //return this._requestValueCollection != null && (this._isCrossPagePostBack 
            //|| (!this._pageFlags[8] && (this.Context.ServerExecuteDepth <= 0 
            //        || (this.Context.Handler != null && !(base.GetType() != this.Context.Handler.GetType()))) && !this._fPageLayoutChanged));

            var pType = this.GetType();
            while (pType.Name != "Page")
                pType = pType.BaseType;
            var _requestValueCollection = pType.GetField("_requestValueCollection", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this);
            Response.Write("_requestValueCollection: " + (_requestValueCollection != null).ToString());
            Response.Write("<br />");

            var _isCrossPagePostBack = pType.GetField("_isCrossPagePostBack", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this);
            Response.Write("_isCrossPagePostBack: " + _isCrossPagePostBack);
            Response.Write("<br />");

            var _pageFlags = pType.GetField("_pageFlags", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this);
            Response.Write("_pageFlags: " + (((int)_pageFlags.GetType().GetField("data", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(_pageFlags) & 8) == 8));
            Response.Write("<br />");
            //SimpleBitVetctor32
            var cType = this.Context.GetType();
            var ServerExecuteDepth = cType.GetProperty("ServerExecuteDepth", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this.Context, null);
            Response.Write("ServerExecuteDepth: " + ServerExecuteDepth.ToString());
            Response.Write("<br />");

            Response.Write("Context_Handler: " + (this.Context.Handler != null));
            Response.Write("<br />");


            var _fPageLayoutChanged = pType.GetField("_fPageLayoutChanged", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this);
            Response.Write("_fPageLayoutChanged: " + _fPageLayoutChanged.ToString());
            Response.Write("<br />");

            Response.Write("base.GetType() != this.Context.Handler.GetType())) " + (base.GetType() != this.Context.Handler.GetType()));
        }

C# to VB

<强>更新

由于你也无法获得控件的值,我怀疑_requestValueCollection为null。 _requestValueCollection是已发布值和查询字符串值的集合。这仍然没有解决问题..