?
Solved

Execute javascript from code behind in asp.net 3.5

Posted on 2008-10-29
5
Medium Priority
?
3,194 Views
Last Modified: 2013-12-17
Scenario:

I have an <asp:repeater> filled with <asp:LinkButton> items.

I add .command and .commandargument to each linkbutton to execute am asp.net method, which will do som LINQ quering in a cached sqlobject based on the content of the commandargument, filll out some <asp:label> and <asp:textbox> items in a hidden DIV and then I need to call a javascript function to open then hidden DIV in a modal window.

My problem is: How can I  call the javascript function ?

In the "RepeaterItem_Command(Object sender, CommandEventArgs e)" method

I have tried to use ClientScript.RegisterStartUpScript(...)  but the code is never entered on the page
and I have tried to use Respons.Write(<SCRIPT> .....</SCRIPT); didn't work either

Tha page_load has been fired already before it gets to the command method, and there is no postback envolved.

0
Comment
Question by:fc_curling
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 8

Expert Comment

by:rpkhare
ID: 22829874
I have tried this way and it is working.
Response.Write("<script language=\"javascript\">")
Response.Write("alert(\"User logged in\");");
Response.Write("</" + "script>");

Open in new window

0
 

Author Comment

by:fc_curling
ID: 22829924
If I do that I get a Script Error in IE : "Error parsing near '<script language="ja'.  Code: 0

samen as when I tried myself
0
 

Author Comment

by:fc_curling
ID: 22829935
From the linenumber it seems that Respons.Write is inserting the tekst right after the <table> tag holdig the <asp:repater> items.
0
 

Author Comment

by:fc_curling
ID: 22829949
This is the steps involved.

1. rendering page and the repeater items.
2. when user clicks one one of the <asp:LinkButton> items, the page_load is fired and after that it calls the command method
3. in the command method I do some LINQ queries and fill out som items in a hidden DIV on the page,
4. at the end of the command methods I want to call a javascript function to handle the modalwindow show of the items in the hidden DIV

it's the last step I'm having trouble with.

0
 

Accepted Solution

by:
fc_curling earned 0 total points
ID: 22872157
I found the solution myself.

It is NOT possible to use ClientScript.RegisterStartUpScript(...)  or response.write when handling the .command event for the <asp:linkbutton control. The response is written before the <html> tag (or so it seems) .

solution were to add the javascript code to call the javascript function in the..OnClientClick property for the linkbutton. When the link is clicked it will fire the .command delegate and the javascript will be executed by the client as well.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question