|
Re: calling javascript function in codebehind
|
|
|
|
|
|
|
|
|
|
Hi,
- Use OnClientClick method
- Also register a hidden control to store ClientID
HTML and JS
function cMC() {
var textBoxID = document.getElementById("textFieldValue").value;
var textBoxValue = document.getElementById(textBoxID).value;
alert(textBoxValue);
}
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="cMC()" /> </form> C# protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) {
ScriptManager.RegisterHiddenField(this, "textFieldValue", TextBox1.ClientID);
} }
|
|
|
|