Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

OnClientClick not getting fired

Posted on 2006-11-06
6
Medium Priority
?
971 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
Technology Partners: 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!

 

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

Technology Partners: 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

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.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

609 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