Why does changing the val of a text input element in jQuery not fire my TextChanged event?
I'm trying to change a value in jQuery that will cause a chain reaction, so to speak, to fire the element's TextChanged event. I've got this server-side code:
-
PDFGenBtnClicked = new TextBox();
PDFGenBtnClicked.ID = "pdfgenbtnclicked";
PDFGenBtnClicked.Text = "no";
PDFGenBtnClicked.Style["display"] = "none";
PDFGenBtnClicked.AutoPostBack = true;
PDFGenBtnClicked.TextChanged += new EventHandler(PDFGenBtnClicked_TextChanged);
. . .
protected void PDFGenBtnClicked_TextChanged(object sender, EventArgs e)
{
GeneratePDF(listOfListItems);
}
...the first part of which causes the following HTML to be rendered (as seen via "View Source"):
input name="ctl00$ctl24$g_5f3fedca_19f7_4bc3_b84e_efbef0c48a33$ctl00$pdfgenbtnclicked" type="text" value="no" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ctl24$g_5f3fedca_19f7_4bc3_b84e_efbef0c48a33$ctl00$pdfgenbtnclicked\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="ctl00_ctl24_g_5f3fedca_19f7_4bc3_b84e_efbef0c48a33_ctl00_pdfgenbtnclicked" style="display:none;" />
I've got this jQuery, which should change the value when a button is clicked:
-
$(document).on("click", '[id$=btnGeneratePDF]', function () {
alert("btnGeneratePDF click was reached");
$('[id$=pdfgenbtnclicked]').val("yes");
});
Note: The jQuery function
is being fired - I
do see the alert after selecting "btnGeneratePDF".
However, even though the text value is presumably being changed, the PDFGenBtnClicked_TextChanged() event is not being fired. Why? Is "val" the wrong thing to use in the jQuery now? Should it be InnerHtml or something else instead?