0

在以下问题上工作超过 5 小时:

Private Sub ModulEdit_PreInit(sender As Object, e As EventArgs) Handles Me.PreInit

    Dim modulid As Integer = 1

    loadeditors(modulid)



End Sub


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

End Sub

Public Sub loadeditors(modulID As Integer)



    PlaceHolder1.Controls.Clear()

    Using dbContext As New EntitiesModel()
        Dim mps As List(Of ef.Modulparameter) = dbContext.Modulparameters.Where(Function(c) c.ModulID = modulID).ToList

        Dim mmid As Int16
        If EditMode.Checked = True Then
            mmid = RadComboBox3.SelectedValue
        End If

        Dim mp As ef.Modulparameter

        For Each mp In mps


            Dim lbl As New Label
            lbl.Text = "<BR>" & mp.Name & "<BR>"
            PlaceHolder1.Controls.Add(lbl)

            Select Case mp.Editor.Name

                Case "textbox1line"

                    Dim con As New TextBox
                    con.ID = mp.ID

                    If EditMode.Checked = True Then
                        Using dbContext2 As New EntitiesModel
                            Try
                                Dim mpa As ef.Menu_modul_paramvalue = dbContext2.Menu_modul_paramvalues.Where(Function(c) c.ModulparameterID = mp.ID And c.Menu_modulID = mmid).First
                                con.Text = mpa.Valuestring

                            Catch ex As Exception
                                con.Text = "AAAA"
                            End Try

                        End Using
                    End If



                    PlaceHolder1.Controls.Add(con)
                    'RadAjaxManagerProxy1.AjaxSettings.AddAjaxSetting(Panel1, con, Nothing)
                    'RadAjaxManagerProxy1.AjaxSettings.AddAjaxSetting(con, con, Nothing)


                Case "radeditor"

                    Dim con As New RadEditor
                    con.ID = mp.ID
                    con.ToolsFile = "\admin\controls\ToolsFile.xml"
                    'con.CssFiles.Add("\Content\frenzy\css\frenzy-orange.css")
                    If EditMode.Checked = True Then
                        Using dbContext2 As New EntitiesModel
                            Try
                                Dim mpa As ef.Menu_modul_paramvalue = dbContext2.Menu_modul_paramvalues.Where(Function(c) c.ModulparameterID = mp.ID And c.Menu_modulID = mmid).First
                                con.Content = mpa.Valuestring

                            Catch ex As Exception
                                con.Content = "BBBB"
                            End Try

                        End Using
                    End If


                    PlaceHolder1.Controls.Add(con)
                    'RadAjaxManagerProxy1.AjaxSettings.AddAjaxSetting(Panel1, con, Nothing)
                    'RadAjaxManagerProxy1.AjaxSettings.AddAjaxSetting(con, con, Nothing)



            End Select




        Next

    End Using


End Sub

我动态添加控件,在 pre_init 中调用上面的代码部分(在 load 和 init 中也尝试了相同的结果)控件的值(文本)在那里直到该行 PlaceHolder1.Controls.Add(con) 在 con.text 之后空的。

控件是在之后添加的,但没有任何值。奇怪的是,在同一个过程中,我添加了另一个控件(标签),其中文本值位于之后的页面上。

添加附加信息:在调试 LoadEditors 时,控件值(文本或内容)始终正确设置。但是然后在页面上(文本框和radeditor)都是空的路由是从预初始化调用的,如很多相关帖子中所述。

4

2 回答 2

1

您正在调用 ModulEdit_Init 中的加载程序。这不应该是 LoadControls 吗?

于 2012-12-19T16:54:58.253 回答
0

我自己修好了:

  • 在将控件添加到占位符之前添加“con.ViewStateMode = System.Web.UI.ViewStateMode.Disabled”
  • 在 RadComboBox3 中也调用“loadeditors()”

问题很可能是,我在页面加载或初始化中加载了编辑器,它得到了正确的值,但随后调用了 RadComboBox3.SelectedIndexChanged 事件,它以某种方式覆盖了这些值

所以我的答案不是一个真正的答案,但它现在有效(我讨厌这样:它有效,但我不知道为什么);)

于 2012-12-20T11:16:44.410 回答