locked
java script RRS feed

  • Question

  • User1125372096 posted

    i have multiple no of control on web form each do post back more than 100 txtbox exist.or it can alos increase i want to know which txtbox do post back with out writing any code on text changed .it is impossible to write code on each text box so what's the solution.

    Tuesday, September 6, 2011 8:50 AM

Answers

  • User-578657687 posted

    Hi,

    i want to write one time and which applicable for all textbox

    Based on your information please try this sample:

      <script type="text/javascript">
            function Change(value) {
                alert(value);
            }
        </script>
    
    <asp:TextBox ID="TextBox2" runat="server" onchange="Change(this.value);"></asp:TextBox>
            <asp:TextBox ID="TextBox3" runat="server" onchange="Change(this.value);"></asp:TextBox>
            <asp:TextBox ID="TextBox4" runat="server" onchange="Change(this.value);"></asp:TextBox>
            <asp:TextBox ID="TextBox5" runat="server" onchange="Change(this.value);"></asp:TextBox>
            <asp:TextBox ID="TextBox6" runat="server" onchange="Change(this.value);"></asp:TextBox>
            <asp:TextBox ID="TextBox7" runat="server" onchange="Change(this.value);"></asp:TextBox>
            <asp:TextBox ID="TextBox1" runat="server" onchange="Change(this.value);"></asp:TextBox>

    But I want to recommend a better approach which custom TextBox to implement your requirement:

    Just need to create a class inherits TextBox like this:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using System.Web.UI;
    
    /// <summary>
    /// Summary description for CusmomTextBox
    /// </summary>
    /// 
    namespace CustomTextBox
    {
        [DefaultProperty(""), ToolboxData("<{0}:MycusTextBox runat=server />")] 
        public class TxtBox:TextBox
        {
            protected override void OnPreRender(EventArgs e)
            {
                this.Attributes.Add("onchange", "javascript:alert(this.value);");
                this.BackColor = System.Drawing.Color.AliceBlue;
                this.ReadOnly = false;
                base.OnPreRender(e); 
            }
        }
    }

    And then register this TextBox control into your page:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <%@ Register Namespace="CustomTextBox" Assembly="App_Code" TagPrefix="AA" %>
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <AA:TxtBox ID="TextBox1" runat="server"></AA:TxtBox>
        </div>
        </form>
    </body>
    </html>
    

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 8, 2011 5:35 AM

All replies

  • User-1621255906 posted

    hello Mohit11,

            u can make this as ur requirement. Set postBack event of every textBox as textBox_textChanged.

             Do ur coding here.

    Regards,

    Pravnitz

    Tuesday, September 6, 2011 9:00 AM
  • User1125372096 posted

    ver terrible ans

    Tuesday, September 6, 2011 9:17 AM
  • User-1062158585 posted

    use textbox textChanged event.

    Tuesday, September 6, 2011 9:24 AM
  • User1125372096 posted

    dont give me this type of ans i wil have to write code on each tet changed

    Wednesday, September 7, 2011 2:46 AM
  • User1125372096 posted

    using java scrpit

    Wednesday, September 7, 2011 2:57 AM
  • User1125372096 posted

    ii wil have to write on each text box i want to write one time and which applicable for all textbox

    Wednesday, September 7, 2011 3:35 AM
  • User2027671353 posted

    Hi friend ,

    create ur own user control TextBox... for that u create common property by using that u can validate ur textbox control by a single method.....

    thanks

    MAGESHBABU K

    Wednesday, September 7, 2011 4:01 AM
  • User-578657687 posted

    Hi,

    i want to write one time and which applicable for all textbox

    Based on your information please try this sample:

      <script type="text/javascript">
            function Change(value) {
                alert(value);
            }
        </script>
    
    <asp:TextBox ID="TextBox2" runat="server" onchange="Change(this.value);"></asp:TextBox>
            <asp:TextBox ID="TextBox3" runat="server" onchange="Change(this.value);"></asp:TextBox>
            <asp:TextBox ID="TextBox4" runat="server" onchange="Change(this.value);"></asp:TextBox>
            <asp:TextBox ID="TextBox5" runat="server" onchange="Change(this.value);"></asp:TextBox>
            <asp:TextBox ID="TextBox6" runat="server" onchange="Change(this.value);"></asp:TextBox>
            <asp:TextBox ID="TextBox7" runat="server" onchange="Change(this.value);"></asp:TextBox>
            <asp:TextBox ID="TextBox1" runat="server" onchange="Change(this.value);"></asp:TextBox>

    But I want to recommend a better approach which custom TextBox to implement your requirement:

    Just need to create a class inherits TextBox like this:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using System.Web.UI;
    
    /// <summary>
    /// Summary description for CusmomTextBox
    /// </summary>
    /// 
    namespace CustomTextBox
    {
        [DefaultProperty(""), ToolboxData("<{0}:MycusTextBox runat=server />")] 
        public class TxtBox:TextBox
        {
            protected override void OnPreRender(EventArgs e)
            {
                this.Attributes.Add("onchange", "javascript:alert(this.value);");
                this.BackColor = System.Drawing.Color.AliceBlue;
                this.ReadOnly = false;
                base.OnPreRender(e); 
            }
        }
    }

    And then register this TextBox control into your page:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <%@ Register Namespace="CustomTextBox" Assembly="App_Code" TagPrefix="AA" %>
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <AA:TxtBox ID="TextBox1" runat="server"></AA:TxtBox>
        </div>
        </form>
    </body>
    </html>
    

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 8, 2011 5:35 AM