Solved

Rebind on a .ascx control event

Posted on 2010-11-19
5
950 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
hi jazz have you managed to solve this yet ?
0
 

Author Closing Comment

by:jazzcatone
Comment Utility
yep ...Thanks much...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
crm development 2 35
Hovering effect 9 28
Hide Tab Page 3 18
Create XML 5 30
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now