Access JavaScript disabled checkbox in server side

  • (2 Pages)
  • +
  • 1
  • 2

25 Replies - 1576 Views - Last Post: 15 February 2018 - 05:52 PM

#16 madhan1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 28-December 17

Re: Access JavaScript disabled checkbox in server side

Posted 13 February 2018 - 03:13 PM

Thanks, yes, I use custome control. We follow some code format in dynamic javascript that we add in code behind. so, i follow that format.

this.Hiddencity.clientId ot Hiddentownship is always null in javascript. why is that?
Was This Post Helpful? 0
  • +
  • -

#17 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6932
  • View blog
  • Posts: 23,566
  • Joined: 05-May 12

Re: Access JavaScript disabled checkbox in server side

Posted 13 February 2018 - 04:44 PM

As I said in post #12:

View PostSkydiver, on 12 February 2018 - 08:37 PM, said:

As I told you before in #1 above, declare the hidden control in the ASPX. With your current code, it does not look like you have added the hidden control to the page.


How did you add your other controls to your custom control? Why are you not following the same procedure to add your hidden control?

Furthermore, this.HiddenCity.ClientID and HiddenTownship are server side. That was the point of all your ugly StringBuilder code: to get the resulting control IDs to the client side.
Was This Post Helpful? 0
  • +
  • -

#18 madhan1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 28-December 17

Re: Access JavaScript disabled checkbox in server side

Posted 14 February 2018 - 06:40 PM

Thanks Skydriver. I added the hidden control the way the custom controls were added in the form. after this, the HiddenCity.CleintId is not null anymore. But I am stuck
how I can add the code with <%= %>.value like below.

document.getElementById('<%= m_hiddenTownship.ClientID %>').value = 'disabled';

the way I added code without <% %>, the value is always empty. Is there any easy way to provide this format in dynamic javascript code, please


define hidden field in aspx: I am not sure how the custom control compiled component is in another project. but I think that project reference is added in this current project. but I am not sure how I can access the custom control fields in aspx page. please help
Was This Post Helpful? 0
  • +
  • -

#19 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6932
  • View blog
  • Posts: 23,566
  • Joined: 05-May 12

Re: Access JavaScript disabled checkbox in server side

Posted 14 February 2018 - 07:05 PM

With custom controls, you would be dealing with a .ASCX file rather than a .ASPX. Something is very wrong if you had to insert your custom controls' child controls directly into the ASPX.

If you are building your Javascript using a string builder, then you do not use the ASP.NET web forms <%= %>. You would follow the same approach you are currently using to get client ids into the Javascript.

baavgai and I were just trying to show you that there are cleaner, and to baavgai's point, more testable, ways of generating the Javascript.

You seem very much out of your depth with this project. I highly suggest that you talk to your supervisor regarding needing additional training regarding ASP.NET web forms.
Was This Post Helpful? 0
  • +
  • -

#20 madhan1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 28-December 17

Re: Access JavaScript disabled checkbox in server side

Posted 15 February 2018 - 11:33 AM

Thanks for the suggestion.

I have defined a HiddenField in .cs file as

public HiddenField HiddenTownship = new HiddenField();

in javascript I am trying

StringBuilder sb = new StringBuilder();
sb.AppendFormat(" var temp = document.getElementById('{0}').value='Y';", HiddenTownship.ClientID


I get the error as 'unable to set property 'value' of undefined or null reference". i need to define the HiddenField in cs file only not in aspx. please help.
Was This Post Helpful? 0
  • +
  • -

#21 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6932
  • View blog
  • Posts: 23,566
  • Joined: 05-May 12

Re: Access JavaScript disabled checkbox in server side

Posted 15 February 2018 - 12:24 PM

Why do you need to define a new class HiddenField? Is that yet another custom control?

*sigh* What did you do to fix the problem for HiddenCity in post #18? Do the same for HiddenTownship.
Was This Post Helpful? 0
  • +
  • -

#22 madhan1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 28-December 17

Re: Access JavaScript disabled checkbox in server side

Posted 15 February 2018 - 12:53 PM

I didn't fix anything for Hiddencity or HiddenTownship yet. I just changed the HTMLInputHidden to HiddenField and getting that error message in javascript.
Was This Post Helpful? 0
  • +
  • -

#23 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6932
  • View blog
  • Posts: 23,566
  • Joined: 05-May 12

Re: Access JavaScript disabled checkbox in server side

Posted 15 February 2018 - 01:21 PM

This is what you said in post #16:

View Postmadhan1, on 13 February 2018 - 05:13 PM, said:

this.Hiddencity.clientId ot Hiddentownship is always null in javascript. why is that?


This is what you said in post #18:

View Postmadhan1, on 14 February 2018 - 08:40 PM, said:

I added the hidden control the way the custom controls were added in the form. after this, the HiddenCity.CleintId is not null anymore.


To me, it sounds like you fixed it.
Was This Post Helpful? 0
  • +
  • -

#24 madhan1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 28-December 17

Re: Access JavaScript disabled checkbox in server side

Posted 15 February 2018 - 01:32 PM

It is not null but when I try to store the value in javascript, i get 'unable to set property 'value' of undefined or null reference". I already defined setter an getter for this.

This post has been edited by madhan1: 15 February 2018 - 01:32 PM

Was This Post Helpful? 0
  • +
  • -

#25 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6932
  • View blog
  • Posts: 23,566
  • Joined: 05-May 12

Re: Access JavaScript disabled checkbox in server side

Posted 15 February 2018 - 04:08 PM

Can you give us an example of the actual generated Javascript and HTML? Is the hidden input present in the HTML? Does the id of the hidden element match the id you are looking for in the Javascript? Currently, it doesn't sound one or both of those are true.
Was This Post Helpful? 0
  • +
  • -

#26 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6932
  • View blog
  • Posts: 23,566
  • Joined: 05-May 12

Re: Access JavaScript disabled checkbox in server side

Posted 15 February 2018 - 05:52 PM

As an aside, moving this to ASP.NET Web Forms forum. This is definitely an ASP.NET Web Forms question, rather than a C# question.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2