D'Arcy from Winnipeg
Musings of a Canadian BizTalk and SOA Developer

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...".

Interesting...

***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.

D


Feedback

# 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

Hey D'Arcy,

my first instinct when I look at that code, is that in the original method call, the url is being passed inside quotes which means it is a string, which means it is most likely being executed by an eval statement or something like that. Here is the line as you put it

"javascript:window.open('http://www.yahoo.com');");"

in the second method call you make a call to GetMyURL which returns a string of the same form as that one above. Have you checked to make sure that the sinlge/double quotations are the same? In the above code you have single quotation marks around the yahoo url. My suggestion would be to check the GetMyURL function to ensure it is returning the string

"javascript:window.open('http://www.yahoo.com');");"

and not

"javascript:window.open("http://www.yahoo.com");");" 5/22/2007 11:15 AM | Shaneo

# 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





 

Please add 6 and 8 and type the answer here: