Solved

OnClientClick not getting fired

Posted on 2006-11-06
6
956 Views
Last Modified: 2012-06-21
Hello Experts,

I have this button and a dropdownbox:

<asp:DropDownList ID="ddlLookupType" AutoPostBack=true CausesValidation=false OnSelectedIndexChanged="showPickList" runat=server>
                <asp:ListItem>Contacts</asp:ListItem>
                <asp:ListItem>Organization</asp:ListItem>
            </asp:DropDownList>

<asp:Button id="btnSearch" runat="server" Text="Search" />
and on load of the page I am adding the OnClientClick attribute as shown below:

            if (ddlLookupType.SelectedValue == "Organization")
            {
                btnSearch.Attributes.Add("OnClientClick", "openOrganizationPopup(); return false;");

            }
            else
            {
                btnSearch.Attributes.Add("OnClientClick", "openContactPopup(); return false;");
            }
But it is not getting fired. If I specify in the html code instead of code behind it works fine. Whats the mistake I am doing.

Please help

Thanks
0
Comment
Question by:rowmark
  • 3
  • 2
6 Comments
 
LVL 29

Expert Comment

by:QPR
ID: 17886557
What is it you are trying to fire?
Isn't onClientClick for confirmation messages and the like returning some info from the server?
If you want to carry our a client side function why not just put onClick='openContactPopup()' onto your <asp:button tag?
0
 

Author Comment

by:rowmark
ID: 17886569
I want to call diff javascript method based on the value from the dropdown thats why I cant specify in the <asp:button tag itself.

 if (ddlLookupType.SelectedValue == "Organization")
            {
                btnSearch.Attributes.Add("OnClientClick", "openOrganizationPopup(); return false;");

            }
            else
            {
                btnSearch.Attributes.Add("OnClientClick", "openContactPopup(); return false;");
            }
0
 
LVL 29

Expert Comment

by:QPR
ID: 17886592
openPopup(ddlLookupType.SelectedValue);

and then handle it in the JS?
is that possible? off the top of my head - haven't got time to test atm
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:rowmark
ID: 17886703
no this doesnt work.
0
 
LVL 10

Accepted Solution

by:
jnhorst earned 250 total points
ID: 17886787
"OnClientClick" is not a valid HTML attribute for the <input> element.  It is, however, a property of the Button class in ASP.NET 2.0.  If you are working in 2.0, instead of using Attributes.Add(), just set the OnClientClick property:

if (ddlLookupType.SelectedValue == "Organization")
{
     btnSearch.OnClientClick = "openOrganizationPopup(); return false;";
}
else
{
     btnSearch.OnClientClick = "openContactPopup(); return false;";
}

This would effectively be the same as doing this:

btnSearch.Attributes.Add("onclick", "openOrganizationPopup(); return false;");

which is what you have to do if you working with ASP.NET 1.1

John

0
 

Author Comment

by:rowmark
ID: 17886809
Thanks John it worked.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Technology Resume 7 71
Crystal Report 13.19  not working with ASP.Net framework 4.5.2 4 109
I need help adding validation to my MVC.Net view 6 23
aspx ascx, c# 7 20
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

730 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