3

I have a site that is using the aspdotnetstorefront platform, although this should pertain to any C# site. There is a custom control in a dll named Account. This has several elements including text boxes for customers to enter name, phone number etc.

I have checked the source code with DotPeek and verified I am using the correct naming conventions.

I am attempting to use the javascript onChange event to copy the first name, last name and phone number to lower boxes when a check box (account information same as billing) is checked. So that if customers select that the information is the same it will be automatically copied as they move from one box to the next.

The odd thing is, this works with some of the text boxes but not others. To make things simple I have removed the JS that copies the contents and replaced it with a pop up box for testing.

This works, when I change the text I get a "Hello World" pop up box:

ctrlAccount.txtFirstName.Attributes.Add("onchange", "alert('hello,world')");

But this does not:

ctrlAccount.txtPhone.Attributes.Add("onchange", "alert('hello,world')");

The error I get is:

CS1061: 'AspDotNetStorefrontControls.Account' does not contain a definition for 'txtPhone' and no extension method 'txtPhone' accepting a first argument of type 'AspDotNetStorefrontControls.Account' could be found

So it looks like the compiler cannot recognize the phone text box. When I look at the rendered page code (When the error has been removed of course) the box is there and the ID is correct.

Reading the source code with DotPeek I see:

public Account()
{

  this._txtFirstName = new TextBox();
  this._txtLastName = new TextBox();
  this._txtEmail = new TextBox();
  this._txtPassword = new TextBox();
  this._txtPasswordConfirm = new TextBox();
  this._txtPhone = new TextBox();

}

private void AssignClientReferenceID()
{
  this._txtFirstName.ID = "txtFirstName";
  this._txtLastName.ID = "txtLastName";
  this._txtEmail.ID = "txtEmail";
  this._txtPassword.ID = "txtPassword";
  this._txtPasswordConfirm.ID = "txtPasswordConfirm";
  this._txtPhone.ID = "txtPhone";      
}

(I've removed a bunch of other fields in the interest of readability). But that certainly looks to me like text box for the phone number should have the idea of "txtPhone" and "txtFirstName" and "txtLastName" work just fine, so why would this fail on only the Phone box?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
valis
  • 235
  • 1
  • 4
  • 15
  • Your Fields have underscores. Isn't that the problem? Or there are properties? – Alireza Jul 12 '14 at 08:23
  • This should work out of the box. Do you have this lines within your createaccount.aspx.cs file? ctrlAccount.Phone = Server.HtmlEncode(CommonLogic.IIF(ThisCustomer.Phone.Length != 0, ThisCustomer.Phone, BillingAddress.Phone)); – Dean Jul 14 '14 at 09:38
  • We really need to see the C# code to know what's wrong. – Austin Mullins Jul 15 '14 at 21:13
  • I wrote this comment on an answer yesterday but wanted for you to see it. """@valis Well, did you recompile the code? I mean if you changed the C# code and did not build the new .dll out of it, even if you restart your IIS you will still use an old .dll.""" - Cheers! – AlexandruB Jul 16 '14 at 15:22
  • This is in a code behind page, it's refrencing things that are in the .dll but none of that is changing. – valis Jul 16 '14 at 19:19

4 Answers4

2

The code you've added to the question show only assignment of IDs and nothing else. I can't see the entire source code of Account control but usually fields with leading underscore are protected or private and, to expose these fields, public properties are used so please check if it's present a public property named txtPhone.

EDIT

ctrlAccount.txtFirstName.Attributes.Add("onchange", "alert('hello,world')");
ctrlAccount.txtPhone.Attributes.Add("onchange", "alert('hello,world')");

Try to press F12 with the caret over txtFirstName or txtPhone on the lines above to see where these property are defined.

P.S.: Do not confuse the names of id and public properties of a class

Marco Sacchi
  • 712
  • 6
  • 21
  • The code shows the public IDs being assinged in the second block. For example private void AssignClientReferenceID() { this._txtFirstName.ID = "txtFirstName"; And in fact addressing txtFirstName works just fine. – valis Jul 16 '14 at 18:12
0

It's VS bug, simple restart should help you.

Alex Zhukovskiy
  • 9,565
  • 11
  • 75
  • 151
  • I was really hoping that was it but, no. I am not even using VS, just editing the code behind in a text editor. I tried restarting the site in IIS but no luck. – valis Jul 07 '14 at 18:33
  • 1
    @valis Well, did you recompile the code? I mean if you changed the C# code and did not build the new .dll out of it, even if you restart your IIS you will still use an old .dll. – AlexandruB Jul 15 '14 at 19:06
0

Right-click the txtFirstName part and choose "Go to definition". Ensure that the txtPhone property is defined nearby and is accessible.

Ark-kun
  • 6,358
  • 2
  • 34
  • 70
0

If you open your project on visual studio, you can right click on txtPhone or txtFirstName and click on "Go to definition". It will take you to the place where it is defined. Maybe txtFirstName is being read from somewhere else where txtPhone does't exist.

I get these kind of warning(not an error) on my application sometimes in compiler however on run time, it recognise the definition and no problem is caused.

Yagzii
  • 286
  • 3
  • 14