渲染usercontrol后,用户控件的gridview内的链接按钮未触发 [英] link button inside gridview of user control is not firing after rendering usercontrol
问题描述
我在用户控件的gridview中有一个链接按钮,当我在我的aspx页面上呈现该用户控件时,链接按钮没有触发,它隐藏了我的usercontrol并重定向到我的aspx页面
用户控制(.ascx)
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)
<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>
用户控制(.ascx.vb)
受保护的子Page_Load(ByVal sender As Object,ByVal e As System.EventArgs)处理Me.Load
BindData()
每行在gridCommunicaiton.Rows中
Dim ReadMoreLinkButton As LinkButton = CType(row.FindControl(ReadMoreLinkButton),LinkButton)
AddHandler ReadMoreLinkButton.Click,AddressOf ReadMoreLinkButton_Click
Next
End Sub
Public Sub BindData()
LoadgridCommunicaiton()
结束子
P rivate Sub LoadgridCommunicaiton()
Dim dtList As DataTable = clsCommon.ListRecommendation(clsAuth.GetEXTMID)
如果dtList.Rows.Count> 0然后
gridCommunicaiton.DataSource = dtList
gridCommunicaiton.DataBind()
gridCommunicaiton.Visible = True
divNorecords .Visible = False
否则
divNorecords.Visible = True
gridCommunicaiton.Visible = False
结束如果< br $>
结束子
#RegionButton_Click
受保护的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。添加(intExfbId,hdnVal.Value)
nvc.Add(isRedirect,True)
clsCommon.RedirectTo页面(wfEXMN.aspx,nvc)
结束次级
#End Region
结束班级
.aspx Page
< webmethod()> _
公共共享功能结果(controlName As String)As String
返回结果(controlName)
结束功能
公共共享功能结果(controlName As String)字符串
尝试
Dim page As New Page ()
Dim userControl As UserControl = DirectCast(page.LoadControl(controlName),UserControl)
userControl.EnableViewState = False
Dim form As新的HtmlForm()
form.Controls.Add(userControl)
page.Controls.Add(表格)
Dim textWriter As New StringWriter()
HttpContext.Current.Server.Execute(page,textWriter,False)
返回textWriter.ToString()
Catch ex As Exception
返回ex.ToString()
结束尝试
结束函数
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
推荐答案
尝试在网格的RowCommand事件中捕获事件。
Try capturing the event within the grid's RowCommand event.
这篇关于渲染usercontrol后,用户控件的gridview内的链接按钮未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!