Click here to Skip to main content
15,908,673 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a link button inside gridview of user control when i render that user control on my aspx page that link button is not firing and its hide my usercontrol and redirect to my aspx page

User Control(.ascx)
XML
<asp:Panel ID="pnlRecommend" runat="server" ScrollBars="Auto" style="width:440px;height:200px; overflow-x: hidden">

<asp:GridView ID="gridCommunicaiton" runat="server" AutoGenerateColumns="false" GridLines="None" EnableViewState="false"
        AlternatingRowStyle-CssClass="odd" RowStyle-CssClass="even" Width="440px" Style="color: Black">
        <HeaderStyle CssClass="gridHeader" HorizontalAlign="Left" />
        <Columns>
            <asp:TemplateField HeaderText="Date" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left">
                <ItemTemplate>
                    <asp:Label ID="lblDate" runat="server" Text='<%# Eval("EXFB_DATE") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Comments" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left">
                <ItemTemplate>
                    <asp:Label ID="lblComments" runat="server" Text='<%# Eval("EXFB_COMMENT") %>'></asp:Label>
                    <asp:LinkButton ID="ReadMoreLinkButton" runat="server" Text="More" CommandArgument='<%#Eval("EXFB_EXMN_ID")%>'
                       CommandName="EditRow" > </asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>


                     </asp:Panel>


User Control(.ascx.vb)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
BindData()
For Each row In gridCommunicaiton.Rows
Dim ReadMoreLinkButton As LinkButton = CType(row.FindControl("ReadMoreLinkButton"), LinkButton)
AddHandler ReadMoreLinkButton.Click, AddressOf ReadMoreLinkButton_Click
Next
End Sub

Public Sub BindData()
LoadgridCommunicaiton()
End Sub

Private Sub LoadgridCommunicaiton()
Dim dtList As DataTable = clsCommon.ListRecommendation(clsAuth.GetEXTMID)
If dtList.Rows.Count > 0 Then
gridCommunicaiton.DataSource = dtList
gridCommunicaiton.DataBind()
gridCommunicaiton.Visible = True
divNorecords.Visible = False
Else
divNorecords.Visible = True
gridCommunicaiton.Visible = False
End If

End Sub

#Region "Button_Click"
Protected Sub ReadMoreLinkButton_Click(ByVal sender As Object, ByVal e As CommandEventArgs)

Dim strExfbID As String
strExfbID = e.CommandArgument.ToString
Dim ExfbID As String = clswpDashBoard.GetEXMNID(strExfbID)
hdnVal.Value = ExfbID
Dim nvc As New NameValueCollection
nvc.Add("intExfbId", hdnVal.Value)
nvc.Add("isRedirect", True)
clsCommon.RedirectToPage("wfEXMN.aspx", nvc)
End Sub
#End Region
End Class

.aspx Page

<webmethod()> _
Public Shared Function Result(controlName As String) As String
Return Results(controlName)
End Function


Public Shared Function Results(controlName As String) As String
Try
Dim page As New Page()
Dim userControl As UserControl = DirectCast(page.LoadControl(controlName), UserControl)
userControl.EnableViewState = False
Dim form As New HtmlForm()
form.Controls.Add(userControl)
page.Controls.Add(form)

Dim textWriter As New StringWriter()
HttpContext.Current.Server.Execute(page, textWriter, False)
Return textWriter.ToString()
Catch ex As Exception
Return ex.ToString()
End Try
End Function
Posted
Comments
Ajay_Saini 9-Oct-13 4:42am    
have you use !IsPostBack while binding data on page load?
sayed farhan 9-Oct-13 4:46am    
thanks Ajay.
yes i have, but still its not working

If Not IsPostBack Then
BindData()
End If

1 solution

Try capturing the event within the grid's RowCommand event.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900