locked
TextBox textchanged event is not working/not firing in asp.net When browser JavaScript disable RRS feed

  • Question

  • Hi team,

    My web page should work if browser JavaScript Enable/disable.

    If browser JavaScript disable then I have to do some kind of complex validation .

     When browser JavaScript disable TextBox textchanged event is not working/not firing in asp.net

     <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="NoJavaScript.WebForm1" %>

     <form id="form1" runat="server" autocomplete="off">

      <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" OnTextChanged="TextBox1_TextChanged"  EnableViewState="true"></asp:TextBox>

        protected void TextBox1_TextChanged(object sender, EventArgs e)

            {

                TextBox2.Text = TextBox1.Text;

            }

     When browser JavaScript enable TextBox textchanged event is working/ firing in asp.net

    Your support/suggestions are highly appreciated and welcome.
    Thank's
    Pradan Prasant Kumar .

    Prasanta De Ultimate http://www.acuvate.com

    Monday, November 9, 2015 8:54 PM

Answers

  • OnTextChanged="TextBox1_TextChanged"

    I believe behind the scenes, somehow JavaScript is being wired up for you automatically, because JavaScript must be wired to make it go to the  TextBox1_TextChanged() event method in the codebehind file, which you manually had to do several years ago. If you didn't do it, then it must be that it is done for you, and you just don't see it.

    Also, as mentioned, you should post to the ASP.NET forum.

    • Proposed as answer by Kristin Xie Tuesday, November 10, 2015 9:14 AM
    • Marked as answer by Kristin Xie Monday, November 23, 2015 1:14 AM
    Monday, November 9, 2015 9:54 PM

All replies

  • First of, ASP.NEt questions belong onto a different main Forum:

    http://forums.asp.net/

    Secondly, no mater how much they look like GUI's, ASP.Net page are still just 1980 HTML Web Formulars.
    Anything they do that can't be done by a Web Formular is a JavaScript thing.
    Runat = "server" implies there is some kind of AJAX Postback happening in the background. The J in AJAX stands for Java script.

    Monday, November 9, 2015 9:11 PM
  • OnTextChanged="TextBox1_TextChanged"

    I believe behind the scenes, somehow JavaScript is being wired up for you automatically, because JavaScript must be wired to make it go to the  TextBox1_TextChanged() event method in the codebehind file, which you manually had to do several years ago. If you didn't do it, then it must be that it is done for you, and you just don't see it.

    Also, as mentioned, you should post to the ASP.NET forum.

    • Proposed as answer by Kristin Xie Tuesday, November 10, 2015 9:14 AM
    • Marked as answer by Kristin Xie Monday, November 23, 2015 1:14 AM
    Monday, November 9, 2015 9:54 PM
  • HI.

    Because the web server control's event on server is raise by client post back action.

    if you disable the client script . the post back script function would be die...

    so there is not  posting back by client . that is not server event firing

    below may help you.

    http://www.c-sharpcorner.com/uploadfile/2f73dd/what-is-postback-in-Asp-Net/



    DON'T TRY SO HARD,THE BEST THINGS COME WHEN YOU LEAST EXPECT THEM TO.





    Tuesday, November 10, 2015 7:00 AM
  • Hi team,

    My web page should work if browser JavaScript Enable/disable.

    Then stay away from anything ASP.net related; nothing starting with <asp....> in your markup. Use pure html (and css) for your markup.

    A basic form can be found at e.g. W3Schools HTML Form Tag

    You can change the method to POST.

    As far as I know (I've never paid attention to it as I have never used it in serious ASP.net site), you can still use code behind but there will not be event handlers for button_clicks etc; in the Page_Load event you will have to determine which button is clicked, extract the get/post data and so on. Be very aware of html/script injection (and obviously of SQL injection if applicable).

    Also pay attention to usability; javascript based menus will not work properly (which is about every single menu that you can find on the web), so you need to use e.g. unordered lists or use a menupage so when a main menu item is clicked, the user is redirected to a page with the submenu items. It's not difficult to do but it requires attention.

    I have always been very reluctant to use javascript, so all my PHP sites (except for the last one) did not use it. When I added ASP.net to my 'repertoire' and seeing how heavily it actually relies on javascript, I gave up on catering for disabled javascript. I barely use any additional javascript ; basically only what ASP.net shoves down my throat.

    Tuesday, November 10, 2015 9:47 AM
  • I have always been very reluctant to use javascript, so all my PHP sites (except for the last one) did not use it. When I added ASP.net to my 'repertoire' and seeing how heavily it actually relies on javascript, I gave up on catering for disabled javascript. I barely use any additional javascript ; basically only what ASP.net shoves down my throat.

    That's pure trouble not knowing JavaScript. An effective Web developer has to know JavaScript to develop effective and dynamic Web base applications.

    The Web developer must know these 3 things:

    1) HTML

    2) JavaScript and JavaScript libraries.

    3) CSS

    With not know all 3, then you are a dead duck and kidding yourself. I was rudely awaken on the JavaScript and not knowing it like I should know it, and I am making that correction on the fly professionally.

    JavaScript may not be VB or C#, but it is damn close to it when doing client side browser programming.

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript

    Tuesday, November 10, 2015 7:13 PM