Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Dynamic text box

Dynamic text box

Scheduled Pinned Locked Moved ASP.NET
css
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sris 426
    wrote on last edited by
    #1

    Dear all, I have a dynamic grid, in that I have textboxes added dynamically.When I enter value in textbox1 and textbox2 in a row,the sum should be calculated and displayed in the third textbox at the time of enytering values. I added event handler at the time of creation of text box.So the handler is getting fired at the time of databind event.But i need that handler should be raised at the time of textbox blur event. Or else you can give your known solution. Thanks in advance, Srinivas Mateti

    A 1 Reply Last reply
    0
    • S sris 426

      Dear all, I have a dynamic grid, in that I have textboxes added dynamically.When I enter value in textbox1 and textbox2 in a row,the sum should be calculated and displayed in the third textbox at the time of enytering values. I added event handler at the time of creation of text box.So the handler is getting fired at the time of databind event.But i need that handler should be raised at the time of textbox blur event. Or else you can give your known solution. Thanks in advance, Srinivas Mateti

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Basically you need javascript to handle this... During databind do like this :

      TextBox tb1 = e.item.FindControl("textbox1") as TextBox;
      TextBox tb2 = e.item.FindControl("textbox2") as TextBox;
      TextBox tb3 = e.item.FindControl("textbox3") as TextBox;

      tb1.Attributes.Add("onblur", "javascript:return refreshValue('" + tb2.ClientId + "','" + tb3.ClientId + "');");
      tb2.Attributes.Add("onblur", "javascript:return refreshValue('" + tb1.ClientId + "','" + tb3.ClientId + "');");

      Now place the function in your page inside a script tag:

      function refreshValue(operand, target){
      try {
      var value1 = parseInt(this.value);
      var value1 = parseInt(document.getElementById(operand).value);
      document.getElementById(target).value = (value1 + value2);
      }
      catch(err) {
      alert(err.description);
      return false;
      }
      return true;
      }

      I think this will solve the issue. Try it. ;)

      Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


      My Latest Articles-->** Simplify Code Using NDepend
      Basics of Bing Search API using .NET
      Microsoft Bing MAP using Javascript

      S 1 Reply Last reply
      0
      • A Abhishek Sur

        Basically you need javascript to handle this... During databind do like this :

        TextBox tb1 = e.item.FindControl("textbox1") as TextBox;
        TextBox tb2 = e.item.FindControl("textbox2") as TextBox;
        TextBox tb3 = e.item.FindControl("textbox3") as TextBox;

        tb1.Attributes.Add("onblur", "javascript:return refreshValue('" + tb2.ClientId + "','" + tb3.ClientId + "');");
        tb2.Attributes.Add("onblur", "javascript:return refreshValue('" + tb1.ClientId + "','" + tb3.ClientId + "');");

        Now place the function in your page inside a script tag:

        function refreshValue(operand, target){
        try {
        var value1 = parseInt(this.value);
        var value1 = parseInt(document.getElementById(operand).value);
        document.getElementById(target).value = (value1 + value2);
        }
        catch(err) {
        alert(err.description);
        return false;
        }
        return true;
        }

        I think this will solve the issue. Try it. ;)

        Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


        My Latest Articles-->** Simplify Code Using NDepend
        Basics of Bing Search API using .NET
        Microsoft Bing MAP using Javascript

        S Offline
        S Offline
        sris 426
        wrote on last edited by
        #3

        Thanks abhishake, Actually here the probles is the client id. All textboxes will be added dynamically.I doent know the textbox name..I will work on your advice. Thanks once again, Srinivas Matetu

        A 1 Reply Last reply
        0
        • S sris 426

          Thanks abhishake, Actually here the probles is the client id. All textboxes will be added dynamically.I doent know the textbox name..I will work on your advice. Thanks once again, Srinivas Matetu

          A Offline
          A Offline
          Abhishek Sur
          wrote on last edited by
          #4

          What do you mean by Dynamic controls. Do you mean the controls will be generated inside DataList's ItemTemplate ? Yes, you can access controls inside

          ItemTemplate

          from codebehind just like I mentioned in my other post. You need to find the control when

          ItemDataBound

          event executes.

          <asp:Datalist....OnItemDataBound="Item_Bound" >
          <itemtemplate>
          <asp:textbox runat="server" id="tb1" />
          </itemtemplate>

          Now from codebehind :

          void Item_Bound(Object sender, DataListItemEventArgs e)
          {
          if (e.Item.ItemType == ListItemType.Item ||
          e.Item.ItemType == ListItemType.AlternatingItem)
          {

             TextBox tb1 = e.Item.FindControl("tb1") as TextBox; //same as the control inside Itemtemplate
          

          }

          }

          Note : You must place Runat = server if you want the control to be found properly using e.Item.FindControl Hope this clears your doubt. "Dont forget to click "Good Answer" if it helped you" ;) ;)

          Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


          My Latest Articles-->** Simplify Code Using NDepend
          Basics of Bing Search API using .NET
          Microsoft Bing MAP using Javascript

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups