Hi Meetu Choudhary,
Here is another demo I worked for you just now.
It uses a Button whose display is "none" to call the function in the Code-Behind and when the users press in the TextBox, a JavaScript funtion will fired to click the Button.
<script type="text/javascript">
function callsub() {
document.getElementById("Hidden1").value = document.getElementById("TextBox1").value
document.getElementById("Button1").click();
}
function moveindex() {
var rng = document.selection.createRange();
rng.moveStart("character", 200);
rng.select();
}
</script>
And also, we need a Hidden field to save the value in the TextBox.
<asp:TextBox ID="TextBox1" runat="server" onkeyup="callsub()" onfocus="moveindex()"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" style="display:none" />
<input id="Hidden1" type="hidden" runat="server" />
Just for the Text, I make the Button to write the current time on the page.
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Write(Now)
TextBox1.Focus()
TextBox1.Text = Hidden1.Value
End Sub
You can write your own code in the Button1_Click event handler.
Best Regards,
Shengqing Yang
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread : )