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. setting value on ClinetClick and reading changed value on OnClik[Server Side]

setting value on ClinetClick and reading changed value on OnClik[Server Side]

Scheduled Pinned Locked Moved ASP.NET
javascriptdesignsysadmintutorialquestion
4 Posts 3 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.
  • K Offline
    K Offline
    K V Sekhar
    wrote on last edited by
    #1

    Hi all, I have a TextBox and Button. The Button have two events 'OnClentClick'(javascript) and 'OnClick'(server side). OnClientClick of button i could able to set the value to textbox and i could see the value in TextBox. But when OnClick of Button i could not able to read the changed value of TextBox. Its giving value which i assigned at design time. But i could see the new value in textbox. Why? whats the reason. How to read that changed value on OnClick(Server Side]. Please suggest me how to do that. Thanks in advance.

    A P 2 Replies Last reply
    0
    • K K V Sekhar

      Hi all, I have a TextBox and Button. The Button have two events 'OnClentClick'(javascript) and 'OnClick'(server side). OnClientClick of button i could able to set the value to textbox and i could see the value in TextBox. But when OnClick of Button i could not able to read the changed value of TextBox. Its giving value which i assigned at design time. But i could see the new value in textbox. Why? whats the reason. How to read that changed value on OnClick(Server Side]. Please suggest me how to do that. Thanks in advance.

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      Can you please show us the code ?

      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

      K 1 Reply Last reply
      0
      • A Abhijit Jana

        Can you please show us the code ?

        Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

        K Offline
        K Offline
        K V Sekhar
        wrote on last edited by
        #3

        Here is the sample code.

        <html xmlns="http://www.w3.org/1999/xhtml" >
        <head runat="server">
        <title>GridView Export</title>
        <script type="text/javascript" language="javascript">
        function ChangeText()
        {
        var tBox = document.getElementById("TextBox1");
        tBox.value = "New Text";
        alert(tBox.value);
        }
        </script>
        </head>
        <body>
        <form id="form1" runat="server">
        <div>
        <asp:TextBox ID="TextBox1" runat="server" Text="Old Text"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" OnClientClick="javascript:ChangeText();" />
        </div>
        </form>
        </body>
        </html>

        the code behid page: Firm1.aspx.cs:

        protected void Button1_Click(object sender, EventArgs e)
        {
        Response.write("New Text"+TextBox1.Text); //out put: "Old Text"[Given at design time]
        }

        please suggest me where i did wrong.

        1 Reply Last reply
        0
        • K K V Sekhar

          Hi all, I have a TextBox and Button. The Button have two events 'OnClentClick'(javascript) and 'OnClick'(server side). OnClientClick of button i could able to set the value to textbox and i could see the value in TextBox. But when OnClick of Button i could not able to read the changed value of TextBox. Its giving value which i assigned at design time. But i could see the new value in textbox. Why? whats the reason. How to read that changed value on OnClick(Server Side]. Please suggest me how to do that. Thanks in advance.

          P Offline
          P Offline
          Pranay Rana
          wrote on last edited by
          #4

          Beacuse field value set by javascript it not available in server side code but you can access value by classical asp pattern string txtvalue = request.form("fieldname")

          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