Login  
Search All Forums
Dart Home | PowerWEB LiveControls for ASP.NET | Custom Development Reply | PowerWEB LiveControls for ASP.NET Topics | Forums   
AuthorForum: PowerWEB LiveControls for ASP.NET
Topic: Problem with bufferedscripot and livelinkbutton
wombel

From: Nürnberg, Germany
Posts: 55
Member Since: 09/22/05
posted June 27, 2006 10:32 AM

I am building a webpart with a livelinkbutton. the button should open a new window on click. I have added this code
Dim link As New LiveLinkButton
link.BufferedScript.Write("onclick","alert('hello');")
it does not work it shows me a alert with the message ';' expected. I tried this code
link.bufferedscript.write("window.open('http://www.microsoft.com');")
I have a livetimer in the same panel and the result was that It opened many windows without click event.
John Talarico



From: Rome, NY USA
Posts: 630
Member Since: 06/01/05
posted June 28, 2006 1:18 PM

The BufferedScript property should only be used to execute script on the client within a LiveControls callback. So, this line is incorrect:
link.BufferedScript.Write("onclick","alert('hello');")

The second line is correct:
link.bufferedscript.write("window.open('http://www.microsoft.com');")

Where is this code being executed? In an event? In page_Load?
bhupi

From: nürnberg, Germany
Posts: 20
Member Since: 06/28/06
posted June 29, 2006 8:30 AM

hi,
This code is being executed in timer_tick event(interval=2000) . I want to open a link in a new window when a user clicks on a link. could you give me some advice on how to add client side script to a livehyperlink so that the link opens in a new window.
John Talarico



From: Rome, NY USA
Posts: 630
Member Since: 06/01/05
posted June 29, 2006 9:37 AM

There are actually two separate controls, a LiveLinkButton and a LiveHyperlink. They both render as hyperlinked text, just as the Microsoft LinkButton and Hyperlink controls, but the LiveLinkButton is better suited for executing server-side code in a server-side Click event where the destination URL is dynamically generated.

For example:
private void LiveLinkButton1_Click(object sender, System.EventArgs e)
{
  LiveLinkButton1.BufferedScript.Write("window.open('http://www.microsoft.com');");
}

Or, if you are dynamically generating the control, on each page_load you would need to add the event handler. If your destination URL is not changing, you can simply use a dynamically generated HTML hyperlink that executes the window.open script in the href attribute without using a LiveLinkButton. 

Without knowing more about the context of the application code and your overall desired behavior it is difficult to be more specific. But, fundamentally, the BufferedScript property set on any LiveControl within a callback (LiveTimer_Tick, etc.) will cause the script to execute on the client when the callback returns. If you attempt to manually add attributes to the controls and insert script, it may interfere with the callback mechanism.
bhupi

From: nürnberg, Germany
Posts: 20
Member Since: 06/28/06
posted June 29, 2006 10:12 AM

Hi,
I fill my live controls in timer_tick event every minute. I will know the url only in this event,there fore I am trying to add onlclick event in timer_tick to open a new window
John Talarico



From: Rome, NY USA
Posts: 630
Member Since: 06/01/05
posted June 29, 2006 10:52 AM

In this sample LiveTimer_Tick event handler I demonstrate dynamic construction of hyperlinks that open new windows when clicked. This sample assumes that a LivePlaceHolder is present on the page.

private void LiveTimer1_Tick(object sender, System.EventArgs e)
{
Random r = new Random();
for (int i = 0; i < r.Next(3,10); i++)
{
HyperLink hl = new HyperLink();
hl.ID = "dynHL_" + i.ToString();
hl.NavigateUrl="javascript:window.open('http://someurl.com');";
hl.Text = DateTime.Now.ToString();
LivePlaceHolder1.Controls.Add(hl);
LivePlaceHolder1.Controls.Add(new LiteralControl("<br/>"));
}
}
Reply | PowerWEB LiveControls for ASP.NET Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX