Link to home
Start Free TrialLog in
Avatar of vs_mkazanova
vs_mkazanova

asked on

Partial Postback via HTML Radio Button in Gridview

I'm creating HTML radiobuttons in GridView dynamically on GridView's RowCreated events as below:
if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Literal output = (Literal)e.Row.FindControl("plcholdRadioButton");
                output.Text = string.Format(
                    @"<input type=""radio"" name=""ContactGroup"" " +
                    @"id=""RowSelector{0} "" onClick=""AJAXPostback('RowSelector{0}');"" value=""{0}""", e.Row.RowIndex);
                if (MainContactSelectedIndex == e.Row.RowIndex)
                {
                    output.Text += @" checked=""checked""";
                    ViewState["MainClientId"] = DataBinder.Eval(e.Row.DataItem, "clid");
                }
                output.Text += " />";
            }

GridView is in UpdatePanel which is hosted in Master Page, when click one of this radio buttons in gridview it fires up the following javascript:

function AJAXPostback(element)
{
    var grgDynControl = document.getElementById('element');
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm._doPostBack('grgDynControl','');
}

These all works fine but it does full page postback instead of partial postback. How can i achieve the partial postback with this system?
Avatar of aibusinesssolutions
aibusinesssolutions
Flag of United States of America image

Since the radio buttons are just plain HTML radio buttons, I would put a linkbutton in the update panel called "lnkUpdate", and then in the onClick event for the radio buttons, just put __doPostBack('lnkUpdate','')

If you have childrenastriggers set to true, it will do a partial postback, if not just add a trigger for lnkUpdate

Avatar of vs_mkazanova
vs_mkazanova

ASKER

Can you post code for this?
if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Literal output = (Literal)e.Row.FindControl("plcholdRadioButton");
                output.Text = string.Format(
                    @"<input type=""radio"" name=""ContactGroup"" " +
                    @"id=""RowSelector{0} "" onClick=""__doPostBack('lnkButton','');"" value=""{0}""", e.Row.RowIndex);
                if (MainContactSelectedIndex == e.Row.RowIndex)
                {
                    output.Text += @" checked=""checked""";
                    ViewState["MainClientId"] = DataBinder.Eval(e.Row.DataItem, "clid");
                }
                output.Text += " />";
            }


Then in your UpdatePanel, add a LinkButton
<asp:LinkButton ID="btnFinished" runat="server" Text="Finished" style="display:none" />  

And if you need a trigger:
<Triggers>
     <asp:AsyncPostBackTrigger ControlID="btnFinished" EventName="Click" />        
</Triggers>
Sorry, that should be lnkButton, not btnFinished.

Then in your UpdatePanel, add a LinkButton
<asp:LinkButton ID="lnkButton" runat="server" Text="Update" style="display:none" />  

And if you need a trigger:
<Triggers>
     <asp:AsyncPostBackTrigger ControlID="lnkButton" EventName="Click" />        
</Triggers>
I've tested but page still flickers, and progress bar on the browser shows up on the bottom.
Is the page live so I can see it?  Or can you post some code?

I just tested this and it is working fine.  The button does an async postback whether it's inside the updatepanel or outside, since the trigger is defined.
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <asp:LinkButton ID="btnFinished" runat="server" Text="Finished" Style="display: none;" />        
        <input type="button" value="button" onclick="__doPostBack('btnFinished','')" />
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnFinished" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>
 
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFinished.Click
    Label1.Text = Now.ToLongTimeString
End Sub

Open in new window

no it's on intranet,
master page holds the update panel which i have contentplaceholder inside
and content page has the gridview that hosts the gridview with radiobuttons.
ASKER CERTIFIED SOLUTION
Avatar of aibusinesssolutions
aibusinesssolutions
Flag of United States of America 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
That was it, as soon as i placed ctl00$lnkButton in doPostBack, it put me back into business.
Thank you for yor help!