Web User Control loaded into updatePanel click events causing entire page to reload

Last post 08-11-2008 5:17 PM by Mikey2008. 0 replies.

Sort Posts:

  • Web User Control loaded into updatePanel click events causing entire page to reload

    08-11-2008, 5:17 PM
    • Member
      point Member
    • Mikey2008
    • Member since 08-11-2008, 5:00 PM
    • Posts 7

     Hi im sorry for having to ask this but i have tried numerous appraoches and i cant figure out where i am going wrong, i have created a web user control call sampleControl i load this dynamically into my main page which contains a panel, i create the sampleControl for the number of records pulled out of my database based on a stored procedure.

    The sampleControl has an updatePanel containing everything else within the web usercontrol, and the page the controls get loaded onto have a scriptmanager ,

    Everything up until this stage is working fine i have methods to set images etc the images all load etc, the user control has an imageButtons that are loaded dynamically using the following function

    Partial Class sampleControl
        Inherits System.Web.UI.UserControl

        Private imageLink(9) As ImageButton

        Public Sub setImage(ByVal id As Integer, ByVal imageName As String)

            If id = 0 Then
                ImageWindow.ImageUrl = "~/Common/samples/images/" & imageName
            End If
            If id >= 0 And id <= 8 Then
                imageLink(id) = New ImageButton
                imageLink(id).ImageUrl = "~/Common/samples/images/" & imageName
                imageLink(id).CssClass = "sample_link"

                AddHandler imageLink(id).Click, AddressOf imageButtonClick
                page_panel.Controls.Add(imageLink(id))

    'previous tried attempt at adding the image changer method
                'imageLink(id).OnClientClick = "changeImage(" & id & ")"

            End If
        End Sub

        Public Sub imageButtonClick(ByVal sender As Object, ByVal e As System.EventArgs)
            ImageWindow.ImageUrl = "~/Common/samples/images/image2.jpg"
        End Sub

    All images display correctly what i want is inside of the web user control is to be able to click on smaller images representing thumbnails and load the current image clicked into the main ImageWindow the problem im having is before i load the images i call a function which determines what type of data is being pulled from the database, this is only called either on a button click on the main page which changes the type or if the page is not postback

     

    the method imageButton click is also just in play for testing

     

    When i click the imageButtons they dont change the image first time and the page stays as it is, the second click whether its a different image even on a different sampleControl reloads the entire site and as a result shows a blank page as the database stuff hasnt kicked in again.

    Ive also tried dynamically instantiating updatepanels from the main samples page and loading the sampleControls into each one individually however no difference in results.

    I was hoping to click the images and the imagechange code just loads the sampleControl up again changing the image in that single sampleControl so nothing needs pulling from the database again and also everything else on the page stays as it is, i know im probably approaching this incorrectly maybe its not even possible im not sure of perhaps im not loading the on click event correctly, if someone can help me even just point me in the direction as to how you might do this i would be very grateful


Page 1 of 1 (1 items)