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