osiris247
asked on
Get value from asp:textbox client side.
Hi
Ok, something i thought was easy has turned out not so much!
I am trying to get the value from an asp:textbox and without postback.
I have this.....
const string _AccountScript = @"
<script language='javascript' type='text/javascript'>
function AddAccount()
{
var chrAccountName = document.getElementById('t xtAccount' ).value;
WinOpen('ToolsPopup.aspx?c hrAccountN ame= + chrAccountName,290,520,'An ame');
//alert('chrAccountName');
return false;
}
</script>
";
ClientScript.RegisterClien tScriptBlo ck(GetType (), "AddAccount", _AccountScript);
in button properties i have AddAccount();
I have debugged as best i can and the getElementById is where it falls over. I can set the var to a const string and it works fine??? My textbox is is without a doubt 'txtAccount' (correct case).
The error i get is 'Object Required'.
The second part....how can i stop the button posting back??
thanks
o
Ok, something i thought was easy has turned out not so much!
I am trying to get the value from an asp:textbox and without postback.
I have this.....
const string _AccountScript = @"
<script language='javascript' type='text/javascript'>
function AddAccount()
{
var chrAccountName = document.getElementById('t
WinOpen('ToolsPopup.aspx?c
//alert('chrAccountName');
return false;
}
</script>
";
ClientScript.RegisterClien
in button properties i have AddAccount();
I have debugged as best i can and the getElementById is where it falls over. I can set the var to a const string and it works fine??? My textbox is is without a doubt 'txtAccount' (correct case).
The error i get is 'Object Required'.
The second part....how can i stop the button posting back??
thanks
o
ASKER
thanks...first part. You were correct the id does have a long prefix. :)
second part.
Its not a button, its a custom control i have inherited from the ImageButton class.
Any ideas?
o
second part.
Its not a button, its a custom control i have inherited from the ImageButton class.
Any ideas?
o
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
i.e. if you have a usercontrol with a textbox (id "txtAccount") in, and have that usercontrol on your webform, the actual ID it will render with will include a prefix to link the textbox to the usercontrol it's embedded in, hence why your JS may not find it
>> The second part....how can i stop the button posting back??
Use a normal HTML button