Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir, i have a projected mathod like:-

VB
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 want to call this mothod between the button.click method. like:-

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

ValidateDate()

End Sub


how can i do it..
Posted
Comments
Tushar sangani 10-Dec-14 0:57am    
Call This Methode Using Your Class Object
Sergey Alexandrovich Kryukov 10-Dec-14 1:12am    
What's wrong with just reading .NET and VB.NET reference manual?
—SA

hi,

use this

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

ValidateDate(send,e)

End Sub
 
Share this answer
 
I Hop You Under Stand By Example


XML
Public Class QueryBuilder
    Inherits System.Web.UI.Page

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

Protected Sub btnstudent_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnstudent.Click
 Dim cs As New QueryBuilder
cs.ValidateDate()

End Sub

End Class
 
Share this answer
 
v3
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
 
Share this answer
 
Comments
TCS54321 10-Dec-14 1:30am    
why u not write code..
Sergey Alexandrovich Kryukov 10-Dec-14 3:50am    
I do write code, but for answering your elementary question it would be more evil than help. To help yourself, you really should read the manual/reference on .NET and VB.NET, including the topic which confuses you. Otherwise your "programming" would be a lot of time waste and frustration.

I answered your question in full and suggest you accept it formally.

—SA
TCS54321 10-Dec-14 1:30am    
i need some ideas to do that by code.
Sergey Alexandrovich Kryukov 10-Dec-14 3:50am    
Didn't I gave you all the basic ideas? Now it's your turn; if you ask some follow-up questions, I'll gladly answer.
—SA
Raul Iloc 10-Dec-14 1:57am    
I agree with you!
You have my 5+.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900