如何调用protected mathod。 [英] how to call protected mathod.

查看:99
本文介绍了如何调用protected mathod。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,我有一个类似的预测方法: -



sir, i have a projected mathod like:-

Protected Sub ValidateDate(ByVal sender As Object, ByVal e As ServerValidateEventArgs)
      If Regex.IsMatch(txtdated.Text, "(((0|1)[1-9]|2[1-9]|3[0-1])\/(0[1-9]|1[1-2])\/((19|20)\d\d))$") Then
          Dim dt As DateTime
          e.IsValid = DateTime.TryParseExact(e.Value, "dd/MM/yyyy", New CultureInfo("en-GB"), DateTimeStyles.None, dt)
          If e.IsValid Then
              ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('Valid Date.');", True)
          End If
      Else
          e.IsValid = False
      End If
  End Sub







i想在button.click方法之间调用这个方法。喜欢: -






i want to call this mothod between the button.click method. like:-

Protected Sub btnstudent_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnstudent.Click

ValidateDate()

End Sub





我该怎么办..



how can i do it..

推荐答案

然后
Dim dt As DateTime
e.IsValid = DateTime.TryParseExact(e.Value, dd / MM / yyyy CultureInfo( en-GB),DateTimeStyles.None,dt)
If e.IsValid 然后
ClientScript.RegisterStartupScript( Me GetType (), alert alert('Valid Date。'); True
结束 如果
Else
e.IsValid = False
结束 如果
结束 Sub
") Then Dim dt As DateTime e.IsValid = DateTime.TryParseExact(e.Value, "dd/MM/yyyy", New CultureInfo("en-GB"), DateTimeStyles.None, dt) If e.IsValid Then ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('Valid Date.');", True) End If Else e.IsValid = False End If End Sub







i想在button.click方法之间调用这个方法。喜欢: -






i want to call this mothod between the button.click method. like:-

Protected Sub btnstudent_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnstudent.Click

ValidateDate()

End Sub





我该怎么做..



how can i do it..


By定义,你只能从声明类或任何派生类调用受保护的方法。

严格来说,还有另一种方法,反射,但是:1)这是一个恶作剧; 2)在你对基础知识充满信心之前,你不应该达到这样的高级主题,你还不知道。



请阅读:http://msdn.microsoft.com/en-us/library/76453kax.aspx [ ^ ]。



如果您不能使用这样的派生类或声明类,请不要问该怎么办。答案是:决定取决于你。您可能不应该使用受保护的方法,甚至需要从根本上修复您的代码设计。无论如何,欢迎您提出相关的后续问题。



-SA
By definition, you can only call a protected method from the declaring class or any of derived classes.
Strictly speaking, there is another way, reflection, but: 1) this is a trick; 2) you should not get to such advanced topics before you make yourself confident with the fundamentals, which you don't know yet.

Please read: http://msdn.microsoft.com/en-us/library/76453kax.aspx[^].

Please, don't ask what to do if you cannot use such a derived class or the declaring class. The answer would be: the decision is up to you. It's possible that you should not use the protected method, or even need to radically fix your code design. Anyway, your related follow-up questions will be welcome.

—SA






使用此





use this

Protected Sub btnstudent_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnstudent.Click

ValidateDate(send,e)

End Sub


这篇关于如何调用protected mathod。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆