Solved

Trying to Cause Full Page Post Back From Update Panel

Posted on 2012-04-04
4
736 Views
Last Modified: 2012-04-06
I have a .aspx page that is dense to say the least. In it there is a modal popup and within that I have an update panel.(The modal may not matter here but I thought it best to mention it.) Within the update panel I have a place where the user will enter some search criteria and the results from the search are displayed in a gridview control. Within each row of the gridview control there is a checkbox for the user to select a particular record.

Upon doing so, the OnCheckedChanged event of the checkbox runs and  it tries to take text from one of the cells  (its a driver name) of the selected row and bind it to a label. This labe is outside both the update panel and the modalpopup.

So what I need I'm pretty sure is this to do is a full page postback when the  OnCheckedChanged event fires so the label outside  can display the selected rows cell text.
The code I have below almost works...(ugh!!!) It does not do the post back on checking a record. However, it seems that when I  go back into the search and uncheck a record, the full postback happens and the labels text is correctly bound. Very weird.

Any direction on what I not understanding and how to fix this is most appreciated. Code is below.
Jason
    protected void chbxselect_OnCheckedChanged(Object sender, EventArgs e)
    {
        CheckBox chbx = (CheckBox)sender;
       
        
        if (chbx.Checked == true)
        {
            GridViewRow row = (GridViewRow)chbx.NamingContainer;
            string drivername = row.Cells[1].Text;
            lblDriverName.Text = drivername;
         
             
            mpedrvsearch.Hide();
            ScriptManager scriptManager = ScriptManager.GetCurrent(Page);

            if (scriptManager != null)
            {

                scriptManager.RegisterPostBackControl(chbx);

            }





        }

    }

Open in new window

0
Comment
Question by:jazzcatone
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
Rouchie earned 500 total points
Comment Utility
Take a look at this:

http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.registerpostbackcontrol.aspx

You'll want to apply it initally on page_load, then every time the panel containing the checkbox is updated.
0
 

Expert Comment

by:ramgunti
Comment Utility
Dear friend ,

Use below code in .aspx
--------------------------------------
<Asp:updatepanel id="uplsearch1" runat="server" update="conditional">
<contentpanel>
<asp:gridview>

your code

</aspGridview>

</contentpanel>
</updatepanel >

<Asp:updatepanel id="uplsearch2" runat="server" update="conditional">
<contentpanel>

your lable

</contentpanel>
<trigger>
<asp:AsyncPostBackTrigger ControlID="gridview1"/>


</trigger>
</updatepanel >

Use below code in .cs
--------------------------------------

 protected void chbxselect_OnCheckedChanged(Object sender, EventArgs e)
    {
        CheckBox chbx = (CheckBox)sender;
       
       
        if (chbx.Checked == true)
        {
            GridViewRow row = (GridViewRow)chbx.NamingContainer;
            string drivername = row.Cells[1].Text;
            lblDriverName.Text = drivername;
         
             
            mpedrvsearch.Hide();
            ScriptManager scriptManager = ScriptManager.GetCurrent(Page);

            if (scriptManager != null)
            {

                scriptManager.RegisterPostBackControl(chbx);

            }





        }
else
        {
            GridViewRow row = (GridViewRow)chbx.NamingContainer;
            string drivername = row.Cells[1].Text;
            lblDriverName.Text = drivername;
         if( lblDriverName.Text .contains(drivername))
{
 lblDriverName.Text .replace(drivername,'' ")
}
             
            mpedrvsearch.Hide();
            ScriptManager scriptManager = ScriptManager.GetCurrent(Page);

            if (scriptManager != null)
            {

                scriptManager.RegisterPostBackControl(chbx);

            }
}
0
 
LVL 25

Expert Comment

by:Rouchie
Comment Utility
You will HAVE to use scriptManager.RegisterPostBackControl(chbx); on Page_Load otherwise it will never cause a full page postback on the first click!
0
 

Author Comment

by:jazzcatone
Comment Utility
ramgunti,
    Unfortunately I have paging on my gridview. So when I click on a page it causes a full postback.
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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

10 Experts available now in Live!

Get 1:1 Help Now