Displaying hidden variable values in text box on button click

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hsegoy1979
    New Member
    • Jun 2008
    • 30

    #1

    Displaying hidden variable values in text box on button click

    Dear All
    Iam new to asp.net. I had a problem. I have a multiline textbox and link buttons say firstname,lastn ame, Emails and corresponding hidden fields with each textbox.My problem is that suppose i typed some text afterwards i press linkbutton firstname(say). so the value in hidden field associated with this link button will display in the text box.

    Thankx In Advance

    Regards
    Yogesh
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    What?
    I'm not clear with what you are trying to do, but javascript should be able to take the value from one control(hidden or otherwise) and put it in another control

    Comment

    • hsegoy1979
      New Member
      • Jun 2008
      • 30

      #3
      Originally posted by Plater
      What?
      I'm not clear with what you are trying to do, but javascript should be able to take the value from one control(hidden or otherwise) and put it in another control
      I want to display value of hidden field on button click in textbox

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Then javascript would be the way of it.

        Something like:
        [code=javascript]
        var theval = document.getEle mentById("MyHid denfieldName"). Value;
        document.getEle mentById("TheTe xtboxToSet").Va lue = theval;
        [/code]

        Comment

        • hsegoy1979
          New Member
          • Jun 2008
          • 30

          #5
          Originally posted by Plater
          Then javascript would be the way of it.

          Something like:
          [code=javascript]
          var theval = document.getEle mentById("MyHid denfieldName"). Value;
          document.getEle mentById("TheTe xtboxToSet").Va lue = theval;
          [/code]
          Thankx
          Again there is an issue if u can help i want that, Suppose initailly i enter text in text box then i click on a linkbutton then the value of hidden field will appear in the textbox after the entered text
          Thankx in advance
          Yogesh

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by hsegoy1979
            Thankx
            Again there is an issue if u can help i want that, Suppose initailly i enter text in text box then i click on a linkbutton then the value of hidden field will appear in the textbox after the entered text
            Thankx in advance
            Yogesh
            Javascript will do it again. The coding is similar to what Plater gave you above. Try it and post your code if you get problems.

            Comment

            • hsegoy1979
              New Member
              • Jun 2008
              • 30

              #7
              <script language="javas cript" type="text/javascript" >
              function DisplayHiddenVa lue()
              {
              debugger;
              var theval = document.getEle mentById('hdnfl d').value;
              alert(document. getElementById( 'hdnfld').value );
              document.getEle mentById('txtdi splay').value = theval;
              }
              </script>

              My problem is suppose i enter text intially Hello afterwards the value in hiddenfield is World When i call above javascript function it will display Hello World

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by hsegoy1979
                <script language="javas cript" type="text/javascript" >
                function DisplayHiddenVa lue()
                {
                debugger;
                var theval = document.getEle mentById('hdnfl d').value;
                alert(document. getElementById( 'hdnfld').value );
                document.getEle mentById('txtdi splay').value = theval;
                }
                </script>

                My problem is suppose i enter text intially Hello afterwards the value in hiddenfield is World When i call above javascript function it will display Hello World
                Moving to Javascript forum.

                Comment

                • hsriat
                  Recognized Expert Top Contributor
                  • Jan 2008
                  • 1653

                  #9
                  [CODE=javascript]var txt = document.getEle mentById('txtdi splay');
                  txt.value = txt.value + ' ' + theval;[/CODE]

                  Comment

                  • hsegoy1979
                    New Member
                    • Jun 2008
                    • 30

                    #10
                    Originally posted by hsriat
                    [CODE=javascript]var txt = document.getEle mentById('txtdi splay');
                    txt.value = txt.value + ' ' + theval;[/CODE]
                    Thankx.
                    Can we take link button and hidden field in gridview and take values from database for our above scenario

                    Comment

                    • hsriat
                      Recognized Expert Top Contributor
                      • Jan 2008
                      • 1653

                      #11
                      Sorry, could not get that. If you can explain...

                      Comment

                      • hsegoy1979
                        New Member
                        • Jun 2008
                        • 30

                        #12
                        Originally posted by hsriat
                        Sorry, could not get that. If you can explain...
                        hi
                        Actually i mean right now iam just taking one link button and one hidden field
                        and applied the above javascript.I want to take more than one link button and hidden field so can i take it in gridview itemtemplate column and call the above javascript

                        Comment

                        • hsriat
                          Recognized Expert Top Contributor
                          • Jan 2008
                          • 1653

                          #13
                          Originally posted by hsegoy1979
                          hi
                          Actually i mean right now iam just taking one link button and one hidden field
                          and applied the above javascript.I want to take more than one link button and hidden field so can i take it in gridview itemtemplate column and call the above javascript
                          Of course you can. You need to make a general function and pass the required arguments to it.

                          If you can show me HTML part of the grid, I can surely tell you what arguments you need to give to the function.

                          Comment

                          • hsegoy1979
                            New Member
                            • Jun 2008
                            • 30

                            #14
                            Originally posted by hsriat
                            Of course you can. You need to make a general function and pass the required arguments to it.

                            If you can show me HTML part of the grid, I can surely tell you what arguments you need to give to the function.
                            <%@ Page Language="C#" AutoEventWireup ="true" CodeFile="TextB oxDisplay.aspx. cs" Inherits="TextB oxDisplay" %>

                            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

                            <html xmlns="http://www.w3.org/1999/xhtml" >
                            <head runat="server">
                            <title>Untitl ed Page</title>
                            <script language="javas cript" type="text/javascript" >
                            function DisplayHiddenVa lue()
                            {
                            debugger;
                            var theval = document.getEle mentById('hdnfl d').value;
                            alert(document. getElementById( 'hdnfld').value );
                            document.getEle mentById ('txtdisplay'). focus();
                            var txtval= document.getEle mentById('txtdi splay').value +" "+ theval;
                            alert(txtval);
                            document.getEle mentById('txtdi splay').value=t xtval;
                            }
                            </script>
                            </head>
                            <body>
                            <form id="form1" runat="server">
                            <div>
                            <table>
                            <tr>
                            <td>
                            <asp:TextBox ID="txtdisplay " runat="server" TextMode="Multi Line" Rows="10"></asp:TextBox>
                            </td>
                            </tr>
                            <tr>
                            <td>
                            <asp:LinkButt on ID="lnkbtn" runat="server" PostBackUrl="ja vascript:void(0 )" OnClientClick=" DisplayHiddenVa lue();">LinkBut ton</asp:LinkButton>
                            </td>
                            <td>
                            <asp:HiddenFiel d ID="hdnfld" runat="server" Value="Diaspark " />
                            </td>
                            </tr>
                            </table>
                            </div>
                            </form>
                            </body>
                            </html>

                            Comment

                            • hsriat
                              Recognized Expert Top Contributor
                              • Jan 2008
                              • 1653

                              #15
                              It would be better if you post the generated HTML (the one which you see in the view source thingie)

                              Comment

                              Working...