I have an aspx.page in which this TextBox lives.
<asp:TextBox ID="txtPolicyNumber" runat="server" AutoPostBack="true" Width="90px" OnTextChanged="txtPolicyNumber_OnBlur"></asp:TextBox>
Every time I click into this TextBox, type something and click away (lose focus) I wish for this method to execute.
VB.NET
Private Sub txtPolicyNumber_OnBlur(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPolicyNumber.TextChanged
txtPlanCode.Text = Company.Applications.ProductionEngine.BusinessAccess.ManualAdjustmentsBusinessAccess.GetPlanCode(txtPolicyNumber.Text)
End Sub
This method basically calls an ExecuteScalar and returns a value from the database.
SQL
SELECT PolicyPlanCode
FROM bo.PolicyTransactions
WHERE PolicyNumber = @policyNumber
AND PolicyTransactionRowNumberAsc = 1
txtPolicyNumber holds the value which is passed in as parameter @policyNumber.
As soon as I load the page this error occurs.
Compiler Error Message: BC30456: 'txtPolicyNumber_OnBlur' is not a member of 'ASP.reporting_manualadjustments_aspx'
What I need to do is when txtPolicyNumber loses focus, txtPolicyNumber_OnBlur should be called and the result from the Sub txtPolicyNumber_OnBlur() should appear in the txtPlanCode.Text textbox.
Any ideas as to why this error comes up? Happy to make any further clarifications.
The Fix
Your page can't see the method because it's private, set it to protected.
Protected Sub txtPolicyNumber_OnBlur(...
Need to decide
You handle the even in two places. One in the tab and the other at the end of the method with the keyword Handle. Chose one, both do the same thing in the end.
If you decided to just use Handles and not do it in the tag, then you can set your method back to Private.
Note
I'm not sure if you are aware, but the browser need to refresh the page to go back to the server. Doing a TextChanged might not do what you expect. Also, rename your method from OnBlur to TextChanged.