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. Problem in Getting the value of as server side hidden control on client side.

Problem in Getting the value of as server side hidden control on client side.

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

    Respected Gurus How to get the value of a hidden server control on client side. I mean i have a control. I m setting its value on the page_load event of my web page. I want its value in one of my javascript function. How to do that. My code is function SetInitialFocus() { var chk=document.forms[0].getElementById('ChkNewEdit').value; if (chk="new") document.forms[0].getElementById('txtName').focus(); else document.forms[0].getElementById('txtContactPerson').focus(); }

    Server side code is:--------- Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load if some condition then ChkNewEdit.value="Edit" else ChkNewEdit.value="New" end sub Thanx in advance...

    S F 2 Replies Last reply
    0
    • M MissionSuccess

      Respected Gurus How to get the value of a hidden server control on client side. I mean i have a control. I m setting its value on the page_load event of my web page. I want its value in one of my javascript function. How to do that. My code is function SetInitialFocus() { var chk=document.forms[0].getElementById('ChkNewEdit').value; if (chk="new") document.forms[0].getElementById('txtName').focus(); else document.forms[0].getElementById('txtContactPerson').focus(); }

      Server side code is:--------- Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load if some condition then ChkNewEdit.value="Edit" else ChkNewEdit.value="New" end sub Thanx in advance...

      S Offline
      S Offline
      Sun Rays
      wrote on last edited by
      #2

      MissionSuccess wrote:

      here u are calling Java Script function on body load.. always client side function will excecute then server side. so before page load u are trying to get value from Java Script so nothing is there, To solve this u have to call java script function after setting hidden's value at server side.

      Thanks, Sun Rays

      1 Reply Last reply
      0
      • M MissionSuccess

        Respected Gurus How to get the value of a hidden server control on client side. I mean i have a control. I m setting its value on the page_load event of my web page. I want its value in one of my javascript function. How to do that. My code is function SetInitialFocus() { var chk=document.forms[0].getElementById('ChkNewEdit').value; if (chk="new") document.forms[0].getElementById('txtName').focus(); else document.forms[0].getElementById('txtContactPerson').focus(); }

        Server side code is:--------- Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load if some condition then ChkNewEdit.value="Edit" else ChkNewEdit.value="New" end sub Thanx in advance...

        F Offline
        F Offline
        faiqshah
        wrote on last edited by
        #3

        there may be two possible problem If the HiddenControl is part of some usercontrol i mean am ascx then you need to get it ClientID.This is because ASP.NET change the ID of control that have a runat="server" . you can see the ID of your control by viewing the Source of the page.check that the ID of your Hidden control in page source is "ChkNewEdit" or some thing like "ctl_100_serer_xxx" . 2 you r calling the function on page load. but at that time the control that you r accessing in the function have not been created yet. you should register your script tag at the end as --- --- var chk=document.forms[0].getElementById('ChkNewEdit').value; if (chk="new") document.forms[0].getElementById('txtName').focus(); else document.forms[0].getElementById('txtContactPerson').focus(); instead of writing function just paste your function source code in script tag don't call the function at page load . it will call automatically when the page is rendered. :)try this it will work best luck Faiq Afridi

        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