ASP.NET - javascript + codeBehin (ie 6+) - Asked By D Money on 03-Jul-09 04:05 PM


Hi,
I received a code of a page, which works like this: if I am entering text in an asp:TextBox and press "Intro" in the code is executed

codeBehin. This is done by handlin the OnTextChanged event with a codeBehin function

All good till here, the problem is the following ...

Now, what I need, is not only run the code of the codeBehin, but also call a javascript function, both while I hit "Intro" on the

asp:TextBox.

I tried to associate the javascript code to the onchange event, but this does not work. The javascript code does not run and the codebehin

runs perfectly.

A solution that occurred to me, but I have no idea whether it is feasible, is to add javascript code to the event OnTextChanged eg

OnTextChanged = "javascript:alert('a');txtCalle_TextChanged" but this does not work.

This is the code for the TextBox control (nothing from the other world):
<asp:TextBox ID="txtCalle" runat="server" Width="327px" OnTextChanged="txtCalle_TextChanged" MaxLength="50"> </ asp: TextBox>


Turning clean, the idea is to be able to execute javascript code and codebehin when I hit "Enter" in a TextBox.

I listen to suggestions,

thanks!

You need to add a client script event to the TextBox - Peter Bromberg replied to D Money on 03-Jul-09 08:14 PM

myTextBox.Attributes.Add("eventName", "javascript:alert('a');txtCalle_TextChanged" );

Where eventName is the name of a valid client-side HTML DOM browser event.


RE - Ravenet Rasaiyah replied to D Money on 03-Jul-09 09:37 PM

HI

Yes

Just you need add attribute the control your java script


protected void Page_load(object sender, eventargs e)
{
if(!Ispostback)
{

txtName.attribute.add("onchange","javascript:alert('ALERT ALERT!!!')");

}

}

Thank you
http://www.codegain.com

Re - Murali Mohan replied to D Money on 03-Jul-09 10:56 PM

Hi,

check this code.

Page_Load()
{
txtName.Attributes.Add("onchange","return IsValidName(this);");
// like that you can specify. do not menction inside the If(!IsPostback)
}
did not work - D Money replied to Ravenet Rasaiyah on 08-Jul-09 12:47 PM
Hi Bill, thanks for taking the time to answer.

I did what you told me but it didn't work. I suppose I am missing something.
I attach my code so you can point me to the right direction.

Thanks!!!
did not work - D Money replied to Peter Bromberg on 08-Jul-09 12:49 PM
Hi Peter.

Thanks for taking the time to answer.

I did what you told me (at least, that's what I think), but it did'nt work for me.
Please, see my replay to Bill to see my code.

Thanks!!!
sorry, here is the code - D Money replied to D Money on 08-Jul-09 12:50 PM
end of post
code - D Money replied to Peter Bromberg on 08-Jul-09 12:57 PM
code

http://www.eggheadcafe.com/fileupload/1303079103_pruebaSlide.zip