Solved

Rebind on a .ascx control event

Posted on 2010-11-19
5
963 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 36

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

624 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