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. reference a server control from within a client side script

reference a server control from within a client side script

Scheduled Pinned Locked Moved ASP.NET
questionjavasysadmintoolsannouncement
3 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.
  • D Offline
    D Offline
    DotNet_Newbie
    wrote on last edited by
    #1

    Hello all, I have a couple of questions, 1- How can I reference a server control from within a client side java script block. Say if I have an onkeypress function on the client side for a control named "abc" and I have a control named "xyz" that is a server control. How can I reference "xyz" control from within the onkeypress function? 2- Once I can reference the server side control "xyz", how can I force it to update, or causes a post back from within the same client side function above. Thank you all for your responses,

    P 1 Reply Last reply
    0
    • D DotNet_Newbie

      Hello all, I have a couple of questions, 1- How can I reference a server control from within a client side java script block. Say if I have an onkeypress function on the client side for a control named "abc" and I have a control named "xyz" that is a server control. How can I reference "xyz" control from within the onkeypress function? 2- Once I can reference the server side control "xyz", how can I force it to update, or causes a post back from within the same client side function above. Thank you all for your responses,

      P Offline
      P Offline
      Paul Riley
      wrote on last edited by
      #2

      Say, for example, your "abc" is a TextBox and "xyz" is a Button: * Create a custom control derived from TextBox (MyTextBox) * Add a property of type Button (MyTextBox.ButtonToUpdate) * Override the OnPreRender event to use Page.RegisterClientScriptBlock to register a javascript function which receives a string (the name of a button) as an argument and processes it however you want. * Override AddAttributesToRender so that it adds an attribute "onkeypress" which calls the javascript funtion using ButtonToUpdate.ClientID Now use your new control in place of the TextBox. It might sound complicated but once you've worked your way through it once, you'll find it easy to do again. Paul

      D 1 Reply Last reply
      0
      • P Paul Riley

        Say, for example, your "abc" is a TextBox and "xyz" is a Button: * Create a custom control derived from TextBox (MyTextBox) * Add a property of type Button (MyTextBox.ButtonToUpdate) * Override the OnPreRender event to use Page.RegisterClientScriptBlock to register a javascript function which receives a string (the name of a button) as an argument and processes it however you want. * Override AddAttributesToRender so that it adds an attribute "onkeypress" which calls the javascript funtion using ButtonToUpdate.ClientID Now use your new control in place of the TextBox. It might sound complicated but once you've worked your way through it once, you'll find it easy to do again. Paul

        D Offline
        D Offline
        DotNet_Newbie
        wrote on last edited by
        #3

        Thank you for your reply

        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