?
Solved

Partial Postback via HTML Radio Button in Gridview

Posted on 2009-02-18
9
Medium Priority
?
910 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?
0
Comment
Question by:vs_mkazanova
  • 5
  • 4
9 Comments
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23677291
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

0
 
LVL 3

Author Comment

by:vs_mkazanova
ID: 23677321
Can you post code for this?
0
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23677349
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>
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23677357
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>
0
 
LVL 3

Author Comment

by:vs_mkazanova
ID: 23677462
I've tested but page still flickers, and progress bar on the browser shows up on the bottom.
0
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23677504
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

0
 
LVL 3

Author Comment

by:vs_mkazanova
ID: 23677611
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.
0
 
LVL 15

Accepted Solution

by:
aibusinesssolutions earned 2000 total points
ID: 23677633
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.
0
 
LVL 3

Author Closing Comment

by:vs_mkazanova
ID: 31548597
That was it, as soon as i placed ctl00$lnkButton in doPostBack, it put me back into business.
Thank you for yor help!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month16 days, 2 hours left to enroll

850 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