c# - how to access and set the value of server control in javascript -
i in need access hidden field , set value something, can access hidden field value in c# code behind.
i used following:
var = document.getelementbyid(id).getattribute("value", true);
but giving undefined or object null
error.
any appreciated.
<asp:button id="backbtn" runat="server" text="go back" onclientclick="callconfirmbox('<%= textbox2.clientid %>)';" onclick="btnback_click" /> <br/> <script type="text/javascript"> function callconfirmbox(id) { var usrresponse; alert("in call confirm box called"); if ('<%=this.test%>') { var usrresponse = window.confirm("do want go without saving data"); } if (usrresponse) //userresponse true { alert(usrresponse); window.location = window.location.href; } else { var e =document.getelementbyid(id).getattribute("value",true); alert(e) } } </script>
put iside
window.onload = function(){ function callconfirmbox(id) { //your code } }
your accessing element before dom finish loading.that's why getting such error.
edit :
suppose id of button backbtn
given in html.
window.onload = function(){ var callconfirmbox = function (id) { //your code } var backbtn = document.getelementbyid('backbtn'); backbtn.onclick = callconfirmbox; }
Comments
Post a Comment