Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using JavaScript can we hide controls in one .ascx based on the RadioButton selection in another .ascx in Asp.Net?
JavaScript
function hideBusActivityECommerce()
{
    myActivity = getActivity(); // ECommerce?
    if(myActivity =="ECommerce")
    {
       document.getElementById('<%=ECommerceSection.ClientID%>').style.display = 'inline';
       document.getElementById('<%=ddl_submission.ClientID%>').value = "";
       document.getElementById('<%=ddl_submission.ClientID%>').disabled = true;
    }
    else
    {
       document.getElementById('<%=ECommerceSection.ClientID%>').style.display = 'none';
       document.getElementById('<%=ddl_submission.ClientID%>').disabled = false;
    }
    
    if(myActivity=="ECommerce" || myActivity=="Retailer Owned")
    {       
        document.getElementById('<%ctl00_ContentPlaceHolder1_Tab2b_cb_Non%>').disable = false;
      document.getElementById('<%ctl00_ContentPlaceHolder1_Tab2b_txt_NonMerchantNo%>').disable = false;
                       document.getElementById('<%ctl00_ContentPlaceHolder1_Tab2b_txt_rate%>').disable = false;
   }
}
Posted
v3
Comments
OmniSource 30-Sep-13 2:43am    
asp.net files get redered as HTML files, so they follow the same rules as any html files within browser. you can do the following to meet your needs.

1) Create a js function which accepts a bool value, and within the function find your element and add to it's style visibility: none
2) On check/uncheck of your radio button, call above function with your bool values.

this should do the job.
Naresh1277 30-Sep-13 3:46am    
document.getElementById('<%ctl00_ContentPlaceHolder1_Tab2b_cb_Non%>').disable=true;
document.getElementById('<%ctl00_ContentPlaceHolder1_Tab2b_txt_NonMerchantNo%>').disable=true;
document.getElementById('<%ctl00_ContentPlaceHolder1_Tab2b_txt_rate%>').disable=true;
above three controls are in different .ascx tab, so when i choose a radio button option in one tab i need to hide these controls in another tab,
What is the problem with this code? Have you debugged?
Did you check if there are any errors listed in FireBug console window?
Naresh1277 30-Sep-13 5:25am    
how can I know the targatInout Id for those controls in another .ascx tab,
If you want to know the IDs of controls, then View the Source of the Web Page in Browser and locate the control's html.

in the first i prefer using Jquery ,
you must add jquery library befor <script> tag that contain on this code.
JavaScript
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.2.min.js">
</script>

JavaScript
function hideBusActivityECommerce()
{
    myActivity = getActivity(); // ECommerce?
    if(myActivity =="ECommerce")
    {
       $("#"+document.getElementById('<%=ECommerceSection.ClientID%>).style.display = 'inline';
       $("#"+<%=ddl_submission.ClientID%>).val("");
       $("#"+<%=ddl_submission.ClientID%>).attr("disabled","true");
    }
    else
    {
       $("#"+<%=ECommerceSection.ClientID%>).css("display","none");
       $("#"+<%=ddl_submission.ClientID%>).attr("disabled","false");
    }
    
    if(myActivity=="ECommerce" || myActivity=="Retailer Owned")
    {       
        $("#"+<%ctl00_ContentPlaceHolder1_Tab2b_cb_Non%>).attr("disabled","false");
      $("#"+<%ctl00_ContentPlaceHolder1_Tab2b_txt_NonMerchantNo%>).attr("disabled","false");
      $("#"+<%ctl00_ContentPlaceHolder1_Tab2b_txt_rate%>).attr("disabled","false");
   }
}
 
Share this answer
 
v2
C#
if(myActivity=="ECommerce" || myActivity=="Retailer Owned")
          {

              document.getElementById('ctl00_ContentPlaceHolder1_Tab2b_cb_NonDiscoverGlobalNetworkGP').style.visibility='hidden';
              document.getElementById('ctl00_ContentPlaceHolder1_Tab2b_txt_NonMerchantNoDiscoverGlobalNetworkGP').style.visibility='hidden';
              document.getElementById('ctl00_ContentPlaceHolder1_Tab2b_ddl_NonClearanceIndDiscoverGlobalNetworkGP').style.visibility='hidden';
              document.getElementById('ctl00_ContentPlaceHolder1_Tab2b_txt_RateDiscoverGlobalNetworkGP').style.visibility='hidden';

          }
          else
          {
              document.getElementById('ctl00_ContentPlaceHolder1_Tab2b_cb_NonDiscoverGlobalNetworkGP').style.visibility='visible';
              document.getElementById('ctl00_ContentPlaceHolder1_Tab2b_txt_NonMerchantNoDiscoverGlobalNetworkGP').style.visibility='visible';
              document.getElementById('ctl00_ContentPlaceHolder1_Tab2b_ddl_NonClearanceIndDiscoverGlobalNetworkGP').style.visibility='visible';
              document.getElementById('ctl00_ContentPlaceHolder1_Tab2b_txt_RateDiscoverGlobalNetworkGP').style.visibility='visible';
          }



with this it is hiding the controls based on the radio button activity
 
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