Calling Codebehind funtion - Easy with Java Script

I was trying hard to call a function, written in .cs file to call it from the .aspx file using JavaScript or any other method finally I succeed and created this piece of code after a research... now want to share it with you people.


script function

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();
}


.aspx source for the button and the textbox

The button is invisible at runtime but used to call the function

asp:TextBox ID="TextBox1" runat="server" onkeyup="callsub()" onfocus="moveindex()">/asp:TextBox>
asp:Button ID="Button1" runat="server" Text="Button" style="display:none" OnClick="Button1_Click1" />

//cs function

protected void Button1_Click1(object sender, EventArgs e)
{
Response.Write(DateTime.Now);
TextBox1.Focus();
TextBox1.Text = Hidden1.Value;
}



Copy and paste above or download the entire code snippet and try it.


Attachments

  • Files (21955-22114-WebSite.zip)
  • Comments

    No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: