之內提交表單我在做的是創建一個網站,其中設計完成後,我使用System.IO.StreamReader將這些html文件讀入主頁面。 和HTML模板裏面有關鍵字像#USER.LOGIN# ,我用函數替換等將usercontrol加載到字符串並在
問題是,我正在替換#USER.LOGIN#用戶控件,有一個登錄窗體。 我有一個函數,它將usercontrol讀入一個字符串,它可以工作。 但由於usercontrol被加載到字符串alle事件沒有跟隨。
所以當我提交登錄表單,沒事,沒事happends(頁文章),但不能得到任何來自表單字段...
注: 我使用的URL重寫如此網址是http://www.domain.com/account/login 其中帳戶是account.aspx和登錄是模式的帳戶是英寸
代碼用於替換的關鍵字中的StreamReader環路(PR線)
If InStr(line, "#USER.LOGIN#") Then
line = line.Replace("#USER.LOGIN#", vbCrLf & userfunc.GetMyUserControlHtml("uc", "account_login.ascx", "/account/login/") & vbCrLf)
End If
而功能至r ead usercontrol
Public Shared Function GetMyUserControlHtml(contextKey As String, controllerfile As String, Optional ByVal formaction As String = "")
Dim myId As Guid = New Guid()
Return userfunc.RenderUserControl("~\Controllers\" & controllerfile, "", myId, formaction)
End Function
Public Shared Function RenderUserControl2(path As String, Optional ByVal formaction As String = "") As String
Using pageHolder As New Page(), _
viewControl As UserControl = DirectCast(pageHolder.LoadControl(path), UserControl), _
output As New StringWriter(), _
tempForm As New HtmlForm()
If formaction <> "" Then
tempForm.Action = formaction
Else
tempForm.Action = HttpContext.Current.Request.RawUrl
End If
tempForm.Controls.Add(viewControl)
pageHolder.Controls.Add(tempForm)
HttpContext.Current.Server.Execute(pageHolder, output, False)
Dim outputToReturn As String = output.ToString()
Return outputToReturn
End Using
End Function
你會怎樣做呢? 我需要在usercontrol中對userlogin進行硬編碼,但仍然可以使用template關鍵字將其放置在任何位置。 這也將是與其他功能(簡報註冊,在線留言板等)
你爲什麼要加載像這樣的用戶控件?您可以隨時將用戶控件動態添加到頁面中... – 2012-02-16 05:08:45
我認爲他正在嘗試爲用戶創建CMS。在那裏他們可以動態地將登錄表單放入任何頁面。 – 2012-02-16 05:11:00
@PhilipBadilla即使在這種情況下,他不能在頁面上動態添加用戶控件嗎? – 2012-02-16 05:18:37