我想使用vb.net将代码后面的变量传递给aspx.page

时间:2013-12-04 18:53:41

标签: asp.net vb.net

我的aspx.page我有一行:

<asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-Mail</asp:Label>
<asp:TextBox  ID="Email" runat="server" TabIndex="4" CssClass="textEntry" CausesValidation="True"></asp:TextBox>
<%MailValidation(Email.Text)%>
<asp:RegularExpressionValidator runat="server" ID="RegExpValidator"
    CssClass="failureNotification" 
    SetFocusOnError="True" ControlToValidate="Email"
    ErrorMessage="<%= ValReturnTxt %>"
    ValidationGroup="RegisterUserValidationGroup">@</asp:RegularExpressionValidator>

在我的代码背后,我有:

Public ValReturnTxt As String
    Public Sub MailValidation(mail As String)
    'Dim retVal As String
    Dim s As Internet = New Internet
    Dim boolVal As Boolean = IsValidEmail(mail)
    ValReturnTxt = Internet._error        
End Sub

后面的代码运行得很好,随时给出了我想要的答案。
Internet是命名空间public class内的Network<%MailValidation(Email.Text)%>行就像我期待的那样 我的问题是,我无法在我的ValReturnTxt

中将ErrorMessage="<%= ValReturnTxt %>"中的RegularExpressionValidator作为txt答案进行分配

1 个答案:

答案 0 :(得分:1)

您可以访问Sub MailValidation()中的控件“RegExpValidator”。

Public Sub MailValidation(mail As String)
    Dim s As Internet = New Internet
    Dim boolVal As Boolean = IsValidEmail(mail)
    RegExpValidator.ErrorMessage = Internet._error ' I added this line.
End Sub