Dynamic UC problems

Discussion in 'ASP .Net' started by David, Jun 18, 2008.

  1. David

    David Guest

    Hi,

    Further to my earlier post about using dynamic usercontrols (which I have
    still yet to solve), I have another problem.


    I am creating the UC in the page by LoadControl. The page itself has a
    submit button that is inside an AJAX UpdatePanel.

    When I submit the page, the contents of the text boxes of the UC don't
    appear to be there.


    I have made a public sub in my UC. I pass an ID to the sub. This happens
    when the submit button on the page is clicked and it works fine (to this
    point).

    sort of like this...

    Page.
    button1_click
    begin
    TravelUC.SaveTravel(ID)
    end


    UC
    public sub SaveTravel(ID as integer)
    begin
    code to save the details.
    end

    However, when I am in the SaveTravel sub routine, the values of my text
    boxes (or drop down box) are seemingly empty. Why would this be? Any ideas
    on how I can fix it?

    Thanks.

    Best regards,
    Dave Colliver.
    http://www.AshfieldFOCUS.com
    ~~
    http://www.FOCUSPortals.com - Local franchises available
     
    David, Jun 18, 2008
    #1
    1. Advertising

  2. David

    David Guest

    Found the problem...

    Here is my code...

    (my Page)
    Partial Class _Default Inherits System.Web.UI.Page

    Dim TravelUC = LoadControl(ResolveUrl("~/UserControls/travel.ascx"))

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

    If Not IsPostBack Then

    LeftPanel.Controls.AddAt(LeftPanel.Controls.IndexOf(Panel5),
    TravelUC)

    End If

    End Sub



    Protected Sub SaveButton_Click(ByVal sender As Object, ByVal e As
    System.EventArgs)

    Dim AttendeeID as integer = 1

    TravelUC.SaveTravel(AttendeeID)

    End Sub



    (My UC)

    Public Sub SaveTravel(ByVal RegistrationID As Integer)

    Dim conn As New SqlConnection(connStr)

    Dim cmd As New SqlCommand("usp_AttendeeTravel")

    cmd.Parameters.Add("@RegID", SqlDbType.Int).Value = RegistrationID

    cmd.Parameters.Add("@TravelBy", SqlDbType.VarChar).Value =
    TravelDDL.SelectedValue

    cmd.Parameters.Add("@PassportName", SqlDbType.VarChar).Value =
    PassportName.Text

    cmd.Parameters.Add("@HomeAddress1", SqlDbType.VarChar).Value =
    HomeAddress.Text

    cmd.Parameters.Add("@HomeAddress2", SqlDbType.VarChar).Value =
    HomeAddress2.Text

    cmd.Parameters.Add("@HomeAddress3", SqlDbType.VarChar).Value =
    HomeAddress3.Text

    Try

    conn.Open()

    funcDB.ExecNonQuery(cmd)

    cmd.Dispose()

    Catch ex As Exception

    Finally

    conn.Close()

    End Try

    End Sub


    What I didn't know is that the ajax call runs the page load on EVERY ajax
    call. As my TravelUC was inside a Not IsPostBack, it wasn't being
    re-loaded, even though it remained on the page (due to ajax not refreshing
    the whole page).

    Moved it outside of the Not IsPostBack and it works.


    Still got my other prob though...

    I want to be able to dynamically load any user control without knowing
    beforehand (as in the above code) what the UC is. i.e. I can have a list of
    user controls but I only want to load whichever specific control by
    attributes known to the page. I don't want to LoadControl all the controls
    on the offchance that I might use it.

    The problem as you can see is that my LoadControl happens outside of any
    function so that the UC is available to any other functions. I would have
    put the loadcontrol inside the pageload, but then I can't call upon any UC
    functions from elsewhere in my page.

    Any ideas?


    Best regards,
    Dave Colliver.
    http://www.AshfieldFOCUS.com
    ~~
    http://www.FOCUSPortals.com - Local franchises available


    "David" <> wrote in message
    news:O%...
    > Hi,
    >
    > Further to my earlier post about using dynamic usercontrols (which I have
    > still yet to solve), I have another problem.
    >
    >
    > I am creating the UC in the page by LoadControl. The page itself has a
    > submit button that is inside an AJAX UpdatePanel.
    >
    > When I submit the page, the contents of the text boxes of the UC don't
    > appear to be there.
    >
    >
    > I have made a public sub in my UC. I pass an ID to the sub. This happens
    > when the submit button on the page is clicked and it works fine (to this
    > point).
    >
    > sort of like this...
    >
    > Page.
    > button1_click
    > begin
    > TravelUC.SaveTravel(ID)
    > end
    >
    >
    > UC
    > public sub SaveTravel(ID as integer)
    > begin
    > code to save the details.
    > end
    >
    > However, when I am in the SaveTravel sub routine, the values of my text
    > boxes (or drop down box) are seemingly empty. Why would this be? Any ideas
    > on how I can fix it?
    >
    > Thanks.
    >
    > Best regards,
    > Dave Colliver.
    > http://www.AshfieldFOCUS.com
    > ~~
    > http://www.FOCUSPortals.com - Local franchises available
    >
     
    David, Jun 19, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick Glos
    Replies:
    0
    Views:
    658
    Rick Glos
    Jul 8, 2003
  2. Chris Thunell
    Replies:
    3
    Views:
    3,455
    Edward
    Jul 21, 2004
  3. =?Utf-8?B?VGVyb3M=?=

    Dynamic Variables? OR Dynamic Controls

    =?Utf-8?B?VGVyb3M=?=, Aug 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    438
    Scott Allen
    Aug 10, 2004
  4. Replies:
    5
    Views:
    5,629
  5. =?Utf-8?B?QkxpVFpXaU5H?=

    Adding dynamic LinkButton to dynamic table

    =?Utf-8?B?QkxpVFpXaU5H?=, Jul 27, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    765
    =?Utf-8?B?QkxpVFpXaU5H?=
    Jul 27, 2005
Loading...

Share This Page