Click here to Skip to main content
15,905,004 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

There is something wrong with my code. I am not able to call this onclient event:

C#
function filterSearch()
{
  var combo = $find('<%=RadComboBox1.ClientID %>');
  var comboValue = document.getElementById(combo.UniqueID + "_value").value;
  if (comboValue == null) 
  {
    alert("You must select a category before processing search!");
    return false;
  }
}


<asp:Button ID="btnSearch" runat="server" Style="float: left; color: black; font-weight: bold" Text="Search" OnClick="btnSearch_Click" OnClientClick="javascript: return filterSearch();" />

I want this to run in the OnClientClick event handler of the button, if no value is selected in combobox. What could be the problem?

Thanks,
Amit
Posted
Updated 9-Nov-10 1:32am
v4
Comments
jim lahey 9-Nov-10 5:32am    
how are you wiring up the event?
AmitChoudhary10 9-Nov-10 5:41am    
<asp:Button ID="btnSearch" runat="server" Style="float: left; color: black; font-weight: bold"
Text="Search" OnClick="btnSearch_Click" OnClientClick="javascript: return filterSearch();" />
AmitChoudhary10 9-Nov-10 7:30am    
is it like impossible to validate combobox for an onClientClick button event?..whats wrong with my code? Anybody please....

Your javascript function does not return true value. So, onClick event will never active. after returning true in OnClientClick, onClick event occur.
Like
function filterSearch()
{
  var combo = $find('<%=RadComboBox1.ClientID %>');
  var comboValue = document.getElementById(combo.UniqueID + "_value").value;
  if (comboValue == null) 
  {
    alert("You must select a category before processing search!");
    return false;
  }
return true;
}

<asp:button id="btnSearch" runat="server" style="float: left; color: black; font-weight: bold" text="Search" onclick="btnSearch_Click" onclientclick="return filterSearch()==true?true:false;" xmlns:asp="#unknown" />
 
Share this answer
 
Comments
Hiren solanki 9-Nov-10 9:31am    
He said the function is not being called, so matter is why it is not calling, your answer could be helpful once function is able to call.
AmitChoudhary10 9-Nov-10 23:30pm    
I don't think its mandatory for javascript function to return true,its just if the condition within the javascript function is not valid,it will automatically run to OnClick event,works for me that way.Any ways the problem was with the javascript code,in finding the item selected in the combo...
Here is the code i am using now,and its working fine...

C#
function filterSearch()
{
       var combo = $find('<%=RadComboBox1.ClientID %>');
       var textbox = document.getElementById("txtSearch");
       if (combo.get_selectedIndex() == null)
       {
           alert("You must select a category before processing search!!");
           return false;
       }
}


and for button same as before--

<asp:Button ID="btnSearch" runat="server" Style="float: left; color: black; font-weight: bold" Text="Search" OnClick="btnSearch_Click" OnClientClick="javascript: return filterSearch();" />
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900