Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to show an alert in asp.net and the alert text should be from textbox1
<div id="myAlert" class="alert alert-danger collapse"  >
    <a id="linkClose" href="#" class="close"</a>
    Fixed Text is here
  </div>

This code will execute on button click, I need to show text of Textbox1 in the place of Fixed Text is here

Again for Clarification : I need to Pass Textbox1 value to the asp.net code

What I have tried:

I got this from google ,But still no idea how to implement after trying many times
function AlertText() {
alert($("#TextBox1").val()); <!-- goal: to display the text from Textbox1. -->
}

Any Help would be highly appreciated
Posted
Comments
F-ES Sitecore 16-Apr-18 7:29am    
Do you want this all to happen in client code without a return trip to the server? If this javascript is on the same aspx page as the textbox then you might just need

alert($("#<%=TextBox1.ClientID%>").val())

but it all depends where your textbox lives.
SulfySul 16-Apr-18 9:18am    
<%=TextBox1.ClientID%>

This solved my problem

Thank you
Ankur\m/ 16-Apr-18 8:18am    
The code in "What I have Tried" section seems correct. Can you share how you are calling it?
SulfySul 16-Apr-18 9:07am    
I have a button to call it
  <button id="btnSubmit" class="btn btn-primary">
    Submit
</button>
Ankur\m/ 18-Apr-18 1:48am    
And how have you hooked up the click event?

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