2013-07-22 60 views
0

我有這個功能,我在頁面INT事件致電LinkBut​​ton的未呈現完全

Protected Function RenderLB(text As String, Id As String, argument As String) As [String] 
     Using Lb = New System.Web.UI.WebControls.LinkButton 
      Lb.Text = text 
      Lb.ID = Id 
      Lb.Attributes.Add("runat", "Server") 
      Lb.CommandName = "RedirectFillsession" 
      Lb.CommandArgument = argument 
      Dim StringBuilder = New System.Text.StringBuilder() 
      Using stringWriter = New System.IO.StringWriter(StringBuilder) 
       Using htmlTextWriter = New System.Web.UI.HtmlTextWriter(stringWriter) 
        Lb.RenderControl(htmlTextWriter) 
       End Using 
      End Using 
      Return StringBuilder.ToString() 
     End Using 
    End Function 

返回的值是錨,但的CommandName和CommandArgument不會呈現 我應該怎麼做來呈現的CommandName和CommandArgument

回答

1

CommandName和CommandArgument從不呈現到輸出HTML中,它們用於隨附的JavaScript中。

另外,您應該將控件添加到控件集合中,而不是手動呈現它。這樣你就可以確定它是整個頁面生命週期的一部分。

Controls.Add(Lb)