之内提交表单我在做的是创建一个网站,其中设计完成后,我使用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