Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Rebind on a .ascx control event

Posted on 2010-11-19
5
Medium Priority
?
965 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 668 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 1332 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 1332 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

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

730 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