Link to home
Start Free TrialLog in
Avatar of Jason Livengood
Jason LivengoodFlag for United States of America

asked on

Trying to Cause Full Page Post Back From Update Panel

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

ASKER CERTIFIED SOLUTION
Avatar of Rouchie
Rouchie
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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);

            }
}
You will HAVE to use scriptManager.RegisterPostBackControl(chbx); on Page_Load otherwise it will never cause a full page postback on the first click!
Avatar of Jason Livengood

ASKER

ramgunti,
    Unfortunately I have paging on my gridview. So when I click on a page it causes a full postback.