We help IT Professionals succeed at work.

Partial Postback via HTML Radio Button in Gridview

vs_mkazanova
vs_mkazanova asked
on
Medium Priority
977 Views
Last Modified: 2012-06-27
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?
Comment
Watch Question

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

Author

Commented:
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>

Author

Commented:
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

Author

Commented:
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.
ah, ok.  That's the problem, having the update panel on the masterpage.  If you view the source the lnkButton probably has an ID of something like ctl00_ContentPlaceHolder1_lnkButton

If so then you'll need to do __doPostBack('ctl00$ContentPlaceHolder1$lnkButton','')

Either that, or you can place the lnkButton on the master page, inside of the update panel, but outside of the contentplaceholder.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
That was it, as soon as i placed ctl00$lnkButton in doPostBack, it put me back into business.
Thank you for yor help!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.