Link to home
Create AccountLog in
Avatar of osiris247
osiris247Flag for United States of America

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('txtAccount').value;
                WinOpen('ToolsPopup.aspx?chrAccountName= + chrAccountName,290,520,'Aname');
                //alert('chrAccountName');
                return false;
            }
        </script>
    ";
ClientScript.RegisterClientScriptBlock(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
Avatar of adathelad
adathelad
Flag of United Kingdom of Great Britain and Northern Ireland image

If you view the source HTML from your browser, can you confirm the textbox does have an id of "txtAccount"?

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
Avatar of osiris247

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
ASKER CERTIFIED SOLUTION
Avatar of adathelad
adathelad
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer