c# - How to call JS function in asp.net -


My problem is that I want to call JS function on the text box attribute "OnTextChanged", the JS function should check that Text is correct in the text box and set the visibility of the button

Here is my asp code:

  ...  ... & lt; / Form & gt; & Lt; / Body & gt; JS (in other file):  
  function valid () {var textbox = '& lt;% = FirstTextBox.ClientID% & gt; '; Var acceptButton = '& lt;% = AddButton.ClientID% & gt;'; Var text = document.getElementById (textbox) .value; Accept Var = document.getElementById (Accept button); If (data is correct) {works ..} and {accept.style.display = 'none'; }}  

And in # code I set the attribute for the text box.

  ClientScriptManager cs = Page.ClientScript; Cs.RegisterClientScriptInclude ("Verify", "Verify.js"); this. First text box. Features. Add ("OnText Change," "Valid ()");  

The JS function is not executed, it seems that the program also did not come within JS Fun Anyone have an idea what I'm doing wrong? Thanks for the help!

I think there are two problems here:

  1. a javascript Event is not OnTextChanged should be updated on onchange or onkeypress depending on the responsibility you see.
  2. The code block in your external javascript value will not be evaluated, which is powerful as NAT, it tries to parse its code randomly for code blocks and try to understand them in the current context not doing.
  3.   function valid (textboxId,  

    btnid) {var textbox = textboxId; Var acceptButton = btnId; Var text = document.getElementById (textbox) .value; Accept Var = document.getElementById (Accept button); If (data is correct) {works ..} and {accept.style.display = 'none'; }}

    C #:

      ClientScriptManager cs = Page.ClientScript; Cs.RegisterClientScriptInclude ("Verify", "Verify.js"); This.FirstTextBox.Attributes.Add ("onchange", string.Format ("Valid ('{0}', '{1}')", First Textbox. Client ID, AddButton.ClientID);  

    Hope that helps.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -