Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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.
 
Share this answer
 
Comments
balongi 1-Mar-11 1:55am    
Let me check this!!
balongi 1-Mar-11 1:59am    
the databinding code already in ispostback condition.. but alert run when i click autopostback true of textbox. first time alert show the value for database but when you change the text of textbox then the variable in alert go blank
Monjurul Habib 1-Mar-11 2:36am    
reason for my +5: that would be my answer too.
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.
 
Share this answer
 
v5
Comments
balongi 1-Mar-11 1:56am    
can u suggest me javascript function for that!
arindamrudra 1-Mar-11 2:04am    
please check my updated answer.
balongi 1-Mar-11 2:14am    
button need two click event for this!..
arindamrudra 1-Mar-11 2:14am    
remove UseSubmitBehavior="false" and check same problem occurs or not?
balongi 1-Mar-11 2:22am    
now! it come to first problem state

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900