在asp.net中处理文本框文本时出现问题 [英] Problem acessing textbox text in asp.net

查看:79
本文介绍了在asp.net中处理文本框文本时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有文本框和按钮,在运行时文本框填充了数据库值.当我单击按钮时,警报显示值"hello"

但是当我用"hi"编辑文本框时,单击警报显示"hello"按钮,但是如果我使文本框自动回发为true,则结果正确并显示"hi".
我不想为文本框自动回传true.因此,当我在运行时单击按钮更改文本时,如何警告显示文本框的值

提前thanx

hi to all i have textbox and button, at run time the textbox fill with database value.when i click the button the alert show the value ''hello''

but when i edit the textbox with ''hi'', and click the button the alert show ''hello'' but if i make textbox autopost back true then it result correct and show ''hi''..

i don''t want autopost back true for textbox.. so how can alert display the value of textbox when i change it text at run time when click the button

thanx in advance

推荐答案

检查您的数据绑定代码.您必须在每次加载页面时绑定文本框.仅在第一次加载页面时才这样做.即在if(!IsPostback)条件内.
Check your data binding code. You must be binding the text box on each page load. Do it only if page loads for the first time. i.e. inside if(!IsPostback) condition.


您也可以使用javascript.

You can use javascript for that also.

<script type="text/javascript">
    function alerttest() 
    {
        var text = document.getElementById(''<%=TextBox1.ClientID%>'').value;
        alert(text);
        return true;
    }
</script>







<asp:Button ID="btnAlert" runat="server" OnClientClick="return alerttest();"
                    Text="Alert" UseSubmitBehavior="false"/>



现在检查一下.



Now check this one.


这篇关于在asp.net中处理文本框文本时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆