Solved

Rebind on a .ascx control event

Posted on 2010-11-19
5
955 Views
Last Modified: 2012-05-10
I have a .aspx page with a ListView control on it. It also has a .ascx control. In the .ascx  the user fills out various search criteria and clicks a button. How do I rebind the list view control on the .aspx page when a button is clicked from the .ascx ? If anyone can point me in the right direction on this it would be greatly appreciated.

Just as an FYI it wasn't my idea to design the search this way....

0
Comment
Question by:jazzcatone
  • 3
5 Comments
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 167 total points
ID: 34176742
one way is to create an event in your user control that triggers when your button onclick fires.
http://asp.net-tutorials.com/user-controls/events/
http://codebetter.com/blogs/brendan.tompkins/archive/2004/10/06/Easily-Raise-Events-From-ASP.NET-ASCX-User-Controls.aspx

then on the event handler on your page, programmatically bind the listview to whatever data is required.
0
 
LVL 4

Assisted Solution

by:Andre412
Andre412 earned 333 total points
ID: 34176865
easy

in your control at the top

Event evCallDataBind()

in the control subroutine that you wish to fire a rebind on the listview control at the end just before the end sub of the last thing you want to do

RaiseEvent evCallDataBind()

now in your listview

We have 3 things
1. the subroutine that will be doing the rebind "Rebind"
2. a find control function that will sniff out your child control ctlChild in the listview, "FindControl"
3. a call to this subroutine in the load

and herer we are
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       
        're attach the events to the controls
        For Each objControl As Control In ListView.Controls
            FindControl(objControl)
        Next
    End Sub

    Sub FindControl(ByVal ctl As Control)
        For Each ctrlItem As Control In ctl.Controls
            If Not ctrlItem Is Nothing AndAlso TypeOf ctrlItem Is ctlChild Then
                AddHandler CType(ctrlItem, ctlChild).evCallDataBind, AddressOf Me.Rebind
            End If
            If ctrlItem.HasControls Then FindControl(ctrlItem)
            'Response.Write(ctrlItem.GetType.ToString & "<br />")
        Next
    End Sub
    
    Sub Rebind()
        lnqEnquiries.DataBind()
        GdEnquiries.DataBind()
    End Sub

Open in new window

0
 
LVL 4

Expert Comment

by:Andre412
ID: 34176888
oops didnt mean to post without explaining

ok so on each load we tie the rountine "Rebind" to the controls event call, thus the control is telling the form to fire Rebind when you raise the event from the control.

Sadly the handler needs to be attached on every load, but the speed is pretty quick so there is no impact on performance

hope this helps, any probs let me know
0
 
LVL 4

Assisted Solution

by:Andre412
Andre412 earned 333 total points
ID: 34189504
hi jazz have you managed to solve this yet ?
0
 

Author Closing Comment

by:jazzcatone
ID: 34207953
yep ...Thanks much...
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question