How can I call a function in code behind file in ASP.NET?

LocationDescription2.Attributes. Add("onclick", "newFunction(what to put here? ) Adds a client side javascript event handler which can't call VB.NET codebehind functions.

You need to wire the event up in VB. NET So it will trigger a postback at which time ASP.NET can invoke the codebehind event handler Your best off defining event handlers in Page_Load though.

LocationDescription2.Attributes. Add("onclick", "newFunction(what to put here? );" Adds a client side javascript event handler which can't call VB.NET codebehind functions.

You need to wire the event up in VB. NET So it will trigger a postback at which time ASP.NET can invoke the codebehind event handler. Your best off defining event handlers in Page_Load though.

And except that there is no click event for that control. – Joel Coehoorn Mar 26 '09 at 16:11 Also: he's using VB. Net – Joel Coehoorn Mar 26 '09 at 16:13 I am following you, Location....("onclick")... adds a client side javascript which will not call Public sub newFunction....? So add LocationDescription2.

Click += newFunction; which raised an error. 2) Would not attributes. Add("onclick")... force a Click event for that control?

– Gail Mar 26 '09 at 16:21 Here's for assumptions :) VB. NET was implied but edited to be more explicit. – Martijn Laarman Mar 26 '09 at 16:21 Gail See Joel Coehoorn's answer which explains how and what event to hook on the server side in VB.NET.

– Martijn Laarman Mar 26 '09 at 16:22.

The Attributes. Add method you're calling only effects the rendered html for the control. The rendered HTML can only directly call javascript functions.

You need this code to be called at the server. Remember to keep the HTML/DOM view of a page and server view of a page separate in your head. To hook up an event in the server view, the vb.Net syntax looks like this: AddHandler LocationDescription2.

EventName, AddressOf newFunction Unfortunately, the DropDownList control does not have a click event, so you will need to replace EventName from my sample with one of the events shown here: msdn.microsoft.com/en-us/library/system.... You'll have to settle for the events included in that last, or do some complicated javascript work to simulate a Click event. Additionally, it's important to remember that when you handle server side events not only does your specific event handler run, but the entire page is rebuilt as well.It does a full postback (ajax aside for the moment). You need to make sure that's really what you intend.

...newFunction raised an error. Originally had the page working with cascading dropdownlist. User wants something that is, at this time, beyond me.

The search for a solution began here, forums.asp. Net/p/1399324/3023937. Aspx#3023937, and I think there is no solution.

Thank you. Gail – Gail Mar 26 '09 at 16:53.

ASP. Net Ajax Toolkit. Look for the Cascading Dropdown Lists and the associated examples.It'll look at act better too.

ASP. Net Ajax Toolkitt.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions