Click here to Skip to main content
15,891,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All

I am not able to find nested user control values in C#. The value is setting by jquery.

given below is the complete scenario :

Master Page D - > Content Page A-> User Control B -> Label C -> Label C value which is setting by jquery and when I want to find this value on content Page A the values always showing default value 91.

Below is the JQuery Code to set value in User Control B:
JavaScript
function GetSelectedValue(ddlId) {

        var objSelectedImage = document.getElementById("SelectedImage");

        var imageUrl = $(ddlId).context.innerHTML;

        var startIndex = imageUrl.indexOf("src=");
        var endIndex = imageUrl.lastIndexOf('"');

        objSelectedImage.src = $(ddlId).context.innerHTML;
        objSelectedImage.src = imageUrl.substring(startIndex + 5, endIndex);
        
        if (!($('#effect').is(":visible"))) {
            //run the effect
            $("#effect").show('blind', 200);
        }
        else {
            $("#effect").hide('blind', 200);
        }

        $("#lblClientValue").html($(ddlId).attr("id"));
        $("#lblServerValue").html('');
        
        $('#<%=hdnCountryCode.ClientID%>').val($(ddlId).attr("id")); 
        
         var a = $(ddlId).attr("id");
         alert(a);
         $('#<%=lblCountryCode.ClientID%>').val($(ddlId).attr("id"));
         
         alert($('#<%=lblCountryCode.ClientID%>').val());
      }


C# Code For User Control B
C#
public Int32 intCountryCode
    {
        get
        {
            if (lblCountryCode.Text != "")
            {
                return int.Parse(lblCountryCode.Text);
            }
            else
            {
                return 91;
            }
        }
        set
        {
            if (!value.ToString().Equals("91"))
            {
                lblCountryCode.Text = value.ToString();
            }
        }
    }

C # Code For User Control A to access intCountryCode value from User Control A
C#
txtCountryCode.Text = UCtxtCountryCode.intCountryCode.ToString();

Every time i am receiving "91" on User Control A even JQuery
JavaScript
alert($('#<%=lblCountryCode.ClientID%>').val());
shows the selected values.

javascript has no issue here. I am getting value of the control in the javascript. The code works on seperate .aspx page and I am able to get the value in .cs file but when I am applying this code to nested user control, the value is not getting in the Content Page User control A. In the user control A I have put another user control B.B user control has a label control and I am trying to get this value in user control A.


please suggest solution.

Thanks
Posted
Updated 13-Dec-13 7:35am
v2
Comments
OriginalGriff 13-Dec-13 13:36pm    
Nope. Shan't.
Stressing the urgency does not help you get your answer. Stressing it in a rude and abrupt way, then doing nothing to help us to help you, like formatting your code so it's easy to read as well just gets peoples backs up.
In this case it means I for one won't even look at your problem, much less give you an answer.

alert($('#<%=lblCountryCode.ClientID%>').text());
 
Share this answer
 
Hi T-Maz,

Thanks for your early reply, I will try your solution and get back to you after 12 hours.

I tried earlier by using hidden field

$('#<%=hdnCountryCode.ClientID%>').val($(ddlId).attr("id"));


but values getting blank on user control B
 
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