473,395 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Execute javascript on a DataGrid's LinkButton click?

Hi,

I have a datagrid with a Templated column below. I want to execute some javascript before the postback to show a hidden "div" tag with static message of "Please Wait..." since the query takes a few seconds. The js function simply sets the css style to display.

<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton Runat="server" CommandName="Select" ID="lbtnCompanyName">
<%# DataBinder.Eval(Container.DataItem, "CompanyName")%>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>

The server side code to add the javascript "onclick" handler to the templated column above...

LinkButton company = (LinkButton)e.Item.Cells[0].Controls[1];
company.Attributes.Add("onclick", "getCompanyInfo()");

The resulting HTML for one of the datagrid rows....

<a id="dgCompanyList__ctl5_lbtnCompanyName" onclick="getCompanyInfo()" href="javascript:__doPostBack('dgPortfolio$_ctl5$l btnCompanyName','')">Acme, Inc.</a>

The js function doesn't seem to get called and the postback occurs anyway. The strange thing is if I say "return getCompanyInfo()" and the function returns false, the message appears but the form submit is cancelled.

Should I execute the js function AFTER the postback is called so it's display until the page is refreshed? If so how do I get it execute after _doPostBack?

Thanks, Dave.

Nov 18 '05 #1
2 5570
You can wrap the <asp:LinkButton> in a <span> control that has the
javascript. Use runat=server and Onclick=javascript, I think.
Then when you click the button the javascript runs first.
For example, I have a Delete button and I wrap in a confirm message box.
If the user hits OK then the delete is processed. But if they Cancel, then
it is not.
--
Joe Fallon

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:57**********************************@microsof t.com...
Hi,

I have a datagrid with a Templated column below. I want to execute some javascript before the postback to show a hidden "div" tag with static
message of "Please Wait..." since the query takes a few seconds. The js
function simply sets the css style to display.
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton Runat="server" CommandName="Select" ID="lbtnCompanyName">
<%# DataBinder.Eval(Container.DataItem, "CompanyName")%>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>

The server side code to add the javascript "onclick" handler to the templated column above...
LinkButton company = (LinkButton)e.Item.Cells[0].Controls[1];
company.Attributes.Add("onclick", "getCompanyInfo()");

The resulting HTML for one of the datagrid rows....

<a id="dgCompanyList__ctl5_lbtnCompanyName" onclick="getCompanyInfo()" href="javascript:__doPostBack('dgPortfolio$_ctl5$l btnCompanyName','')">Acme,
Inc.</a>
The js function doesn't seem to get called and the postback occurs anyway. The strange thing is if I say "return getCompanyInfo()" and the function
returns false, the message appears but the form submit is cancelled.
Should I execute the js function AFTER the postback is called so it's display until the page is refreshed? If so how do I get it execute after
_doPostBack?
Thanks, Dave.

Nov 18 '05 #2
You need to have return in onclick event. So the "return getCompanyInfo()"
is correct, did you check in your js function to make sure there is return
true at the end.
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:ei**************@tk2msftngp13.phx.gbl...
You can wrap the <asp:LinkButton> in a <span> control that has the
javascript. Use runat=server and Onclick=javascript, I think.
Then when you click the button the javascript runs first.
For example, I have a Delete button and I wrap in a confirm message box.
If the user hits OK then the delete is processed. But if they Cancel, then
it is not.
--
Joe Fallon

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:57**********************************@microsof t.com...
Hi,

I have a datagrid with a Templated column below. I want to execute some javascript before the postback to show a hidden "div" tag with static
message of "Please Wait..." since the query takes a few seconds. The js
function simply sets the css style to display.

<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton Runat="server" CommandName="Select" ID="lbtnCompanyName"> <%# DataBinder.Eval(Container.DataItem, "CompanyName")%>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>

The server side code to add the javascript "onclick" handler to the

templated column above...

LinkButton company = (LinkButton)e.Item.Cells[0].Controls[1];
company.Attributes.Add("onclick", "getCompanyInfo()");

The resulting HTML for one of the datagrid rows....

<a id="dgCompanyList__ctl5_lbtnCompanyName" onclick="getCompanyInfo()"

href="javascript:__doPostBack('dgPortfolio$_ctl5$l btnCompanyName','')">Acme, Inc.</a>

The js function doesn't seem to get called and the postback occurs
anyway. The strange thing is if I say "return getCompanyInfo()" and the function
returns false, the message appears but the form submit is cancelled.

Should I execute the js function AFTER the postback is called so it's

display until the page is refreshed? If so how do I get it execute after
_doPostBack?

Thanks, Dave.


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: THM5101 | last post by:
Hello I have two problems with my dataGrid. I created dataGrid with 4 columns. The first and the last one are LinkButton type, the second and third are Bound Column type. My problems are:...
0
by: sameer mowade via .NET 247 | last post by:
Hello All, I have problem while dynamically removing row from the Datagrid which i have added dynamically as shown in the following code snippet. The problem is that while removing dynamically...
12
by: Mark Fox | last post by:
Hello, I am attempting to do something very simple. I have a page MainPage.aspx and a popup window Popup.aspx. When users click on the linkbutton in the popup window I am looking to do some...
0
by: Steve | last post by:
I have a datagrid that is created at run time DataGrid dgG = new DataGrid(); BoundColumn bcB; dgG.CellPadding = 5; dgG.CellSpacing = 0; dgG.GridLines = GridLines.Both; dgG.CssClass =...
12
by: Daniel Walzenbach | last post by:
Hi, I want to display a Label in a DataGrid according to some condition. I therefore check whether the condition is true in the ItemDateBound EventHandler of the DataGrid. Unfortunately the...
2
by: Fluxray | last post by:
--Background: I have a webform including a datagrid. The datagrid is using template. Its ItemTemplate is used to display a look-up-table with labels. its EditItemTemplate is used to edit a row in...
4
by: JD | last post by:
Hello Everyone, I am writing a asp.net page using vb.net with a datagrid control. I am trying to detect when a row is clicked on in the grid. And I am not sure how to do this, if anyone has any...
2
by: Hardy Wang | last post by:
Hi all, We have DataGrid control in Web Form, our client requires to be able to click anywhere of a row to fire the event same as LinkBotton column is clicked. We we did in ASP.NET 1.1 is in...
2
by: johnlim20088 | last post by:
Hi Can anyone help me? I have a Javascript function in my test.aspx as follow:- <script language="Javascript"> function confirm_save() { if (confirm("Are you sure you want to save this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.