D'Arcy from Winnipeg
Solution Architecture, Business & Entrepreneurship, Microsoft, and Adoption

More Fun with Sharepoint 2007 and Web Parts

Tuesday, May 22, 2007 8:51 AM

Hmmm...so I have a LinkButton that I'm adding to my web part. I've got code in my CreateChildControls method that has this line:

lnkExportAll.Attributes.Add("OnClick", "javascript:window.open('http://www.yahoo.com');");

When I run the code with this line, everything is fine. However, I have another method in the web part that will dynamically create a URL based on parameters passed in, so I try to do this:

lnkExportAll.Attributes.Add("OnClick", GetMyURL(true, false));

Don't worry about the true/false values...they just set things in the method. The GetMyURL method just uses a string-builder to build a javascript:window.open(...) type of line and returns it.

The problem though is that when I use my GetMyURL method in the line, which is in the CreateChildControls method, it fails when you run it...it gives one of those wonderful "Error...to troubleshoot Sharepoint, please click this hyperlink that does absolutely nothing of value...".


***EDIT: So I figured out what the issue was...as it always tends to be, it was a stupid mistake: I had an unnecesary call to a method that re-filled a grid with data in my GetMyURL method...but because of where I was calling it in my code, the actual grid hadn't been created yet so it was erroring out. I didn't need it in there anyway, so all is now good.



# re: More Fun with Sharepoint 2007 and Web Parts

...Thats more like it! lol
(sorry, couldnt resist) 5/22/2007 9:12 AM | Mark From London

# re: More Fun with Sharepoint 2007 and Web Parts

It's not the output. I have two other links that use the same function, but they're set outside the CreateChildControls method. So the output is fine...it seems to be something with calling a function from within that method.

D 5/22/2007 3:05 PM | D'Arcy from Winnipeg

# re: More Fun with Sharepoint 2007 and Web Parts

Did you try surrounding GetMyURL(true, false) with double quotes like so?

"GetMyURL(true, false)" 5/22/2007 3:21 PM | Shaneo

# re: More Fun with Sharepoint 2007 and Web Parts

sorry, scratch that. I was assuming GetMyURL(true, false) was a javascript function, it's clear from your code now that this is a server side method call

5/22/2007 3:27 PM | Shaneo

Post a comment