C# 在aspx页面内加载ascx时,IsPostBack始终为真

C# 在aspx页面内加载ascx时,IsPostBack始终为真,c#,asp.net,vb.net,C#,Asp.net,Vb.net,在我的aspx页面中,单击一个按钮,我正在加载ascx,我的问题是: 单击按钮后,我将执行加载ascx的代码,当ascx进入页面时,加载事件IsPostBack()始终为真 我怎样才能修好它 1) 。单击按钮后,我将使用以下代码: userControls.Controls.Clear() lblParkingViolation.Text = "New Violation" userControls.Controls.Add((Page.LoadControl

在我的aspx页面中,单击一个按钮,我正在加载ascx,我的问题是: 单击按钮后,我将执行加载ascx的代码,当ascx进入页面时,加载事件IsPostBack()始终为真

我怎样才能修好它

1) 。单击按钮后,我将使用以下代码:

  userControls.Controls.Clear()
        lblParkingViolation.Text = "New Violation"
        userControls.Controls.Add((Page.LoadControl(Page.ResolveUrl("~/Controls/ParkingViolation/pViolationNew.ascx"))))
2) 。触发上述代码后,我将自动进入ascx的Page_Load事件:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        RetrieveAllQueryStringParams()

        If IsPostBack() Then
            GenerateControls()
            GenerateDataSets()
        End If

        'Dim id As String = Page.Request.Params("__EVENTTARGET")
        ''id of the control that cause postback.

        ''myusercontrol1 is the id of your user control
        '' dont do any thing here post back caused by user control
        'If Not String.IsNullOrEmpty(id) AndAlso id.Contains("myusercontrol1") Then
        '    'Do your thing

    End Sub

注释中的代码对我无效,因为它总是空的。

这是因为它是回发。框架没有问题。问题是你不理解回发是什么。我理解回发的意思,这不是问题所在。回发是正确的,因为它是回发。问题是如果我试图从ascx上的另一个控件回发,它不会触发。@HuyZukerman,那么你需要发布代码,并向我们展示你在做什么,因为它可能应该是。