?
Solved

OnClientClick not getting fired

Posted on 2006-11-06
6
Medium Priority
?
965 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
[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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

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

Accepted Solution

by:
jnhorst earned 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
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

765 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