Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling code behind function from user control 2

Status
Not open for further replies.

developer155

Programmer
Jan 21, 2004
512
US
I have a user control and I have a href link on that control. When the link is clicked I need to bring up a pop up. So I added a C# function in code-behind to fire a pop up (there are some complex conditions) and I am trying to call that function from A href tag HTML tag of the user control like this:
<a href....... onclick="<%FirePopUp();%>">
but it is not working, I am trying to debug but it does not go into the function when I click on the link
Am I doing this wrong?

thanks
 
Use a server side hyperlink and add the javascript through the Attributes.Add method.
 
The control is used by a lot of pages and I really cant change it to server side. There is no way around it? I cant call code behind function from onclick event of the href?
 
Alternatively, you could use a LinkButton


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ca8msm, I cant change the html link to anything, it is used by a lot of pages
 
I don't see what affect it would have on other pages if you changed it...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Why can't you change the control? It doesn't matter how many pageus use the control. The point of a user control is to store common objects and functionality that are used by many pages in one control. Then you only change in one place.
 
this is for a high profile web site and we cannto risk anything. This should be a quick 1-2 day project. If I change the control we need to regression test the whole site, and this is not happening right now.
Do you know any way around it?
 
Also,
even if I use Attribute, the function that checks if a pop up shoudl be opened is in C#, it is not client side. Can I register C# code behind function to Attribute, liek
this.RegisterStartupScript(C# function)
 
Using a server control rather than a HTML control doesn't affect anything as the server control only renders HTML anyway. Also, you are going to be modifying the HTML control and testing that so if it is used on lots of pages you'll have to do all that testing anyway, won't you?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I don't see anyway of calling a serverside function by clicking an HTML hyperlink. You will need to use a server side control.
 
thanks everyone!
So I added an image button and adding an attribute like this to it:
ImageButton_GetDriveMap.Attributes.Add("onclick",this.PopUp());

PopUp is a code-behind function that checks if pop up shoudl display. It will return window.open(....) if it should, otherwise it will return empty string)
Everything is fine, the function PopUp returns correct value, but after Attributes.Add is executed, I get IE message, soemthing about invalid reference. Any idea why?
 
What is the whole error you are getting? Also, where are you adding(event) the attribute to the button?
 
Guys, thanks for all your help.
The error was due to an actual error in Java Script.
I fixed it and everything works fine.
Thanks again for your expert advises
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top