Monday, June 3, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
115
rated 0 times [  117] [ 2]  / answers: 1 / hits: 34177  / 12 Years ago, tue, june 26, 2012, 12:00:00

I have an asp:TextBox that looks like the following



<asp:TextBox runat=server AutoPostBack=True ID=txtG1 ontextchanged=txtG1_TextChanged onmouseout=javascript:RefreshIt(this)/>


and a Javascript function RefreshIt() that correctly fires each time I mouseout of the textbox.



I'm trying to have the mouseout event trigger the ontextchanged event of the asp:TextBox.



Various Stck Overflow posts have recommended the following techniques, which do not seem to work:



function RefreshIt(selectObj){
selectObj.ontextchanged();
}

function RefreshIt(selectObj){
selectObj.fireEvent('ontextchanged');
}


Any help would be appreciated.


More From » c#

 Answers
7

See: https://stackoverflow.com/a/3777/892536



Using this link, I was able to come up with something that produced the same results you are looking for. Not sure if this is okay for your application or not, but it works:



Aspx:



Changed the RefreshIt function to do a postback with an argument:



  <script type=text/javascript>
function RefreshIt(selectObj) {
__doPostBack('<%= Page.ClientID %>', selectObj.name);
}
</script>

</head>
<body>
<form id=form1 runat=server>
<div>

<asp:TextBox runat=server AutoPostBack=True ID=txtG1 OnTextChanged=txtG1_TextChanged
onmouseout=javascript:RefreshIt(this); />

<br />
<br />
Text Changed:&nbsp;

<asp:Label ID=Label1 runat=server></asp:Label>

</div>
</form>
</body>


Code Behind:



Added 'IPostBackEventHandler' to the page and handled the 'RaisePostBackEvent' function:



public partial class _Default : System.Web.UI.Page, IPostBackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{

}

public void RaisePostBackEvent(string Arg)
{
if (txtG1.ID == Arg)
txtG1_TextChanged(txtG1, null);
}

protected void txtG1_TextChanged(object sender, EventArgs e)
{
Label1.Text = System.DateTime.Now.ToString();
}
}

[#84641] Tuesday, June 26, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
trinity

Total Points: 591
Total Questions: 102
Total Answers: 106

Location: Singapore
Member since Sun, Jul 25, 2021
3 Years ago
trinity questions
Fri, Jan 14, 22, 00:00, 2 Years ago
Tue, Apr 27, 21, 00:00, 3 Years ago
Sun, Mar 14, 21, 00:00, 3 Years ago
;