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:
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
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
txtCountryCode.Text = UCtxtCountryCode.intCountryCode.ToString();
Every time i am receiving "91" on User Control A even JQuery alert($('#<%=lblCountryCode.ClientID%>').val()); shows the selected values.
please suggest solution.
Thanks

Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Dec 13, 2013, 6:46 AM EST
First extract the javascript code to separate file & include it wherever you want.
Try to avoid using IDs to identifying the controls, instead use class names.
Make sure that you are resetting the values on PostBack.
Vishnu Narayan MishraRank #4,239 · 356 reputationPosted Dec 13, 2013, 7:30 AM EST
Thanks for the early response. Dear Sir javascript has no issue herer. 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.
txtCountryCode.Text = UCtxtCountryCode.intCountryCode.ToString();
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Dec 13, 2013, 8:34 AM EST
var ctrlA = this.FindControl("UCtxtCountryCode"), ctrlB;
if(ctrlA != null)
{
ctrlB = ctrlA.FindControl("intCountryCode");
}
if(ctrlB != null)
{
var value = vtrlB.Text;
}
Vishnu Narayan MishraRank #4,239 · 356 reputationPosted Dec 13, 2013, 9:18 AM EST
I already tried this
xtCountryCode.Text = UCtxtCountryCode.intCountryCode.ToString();
values are lost while post back.
Please debug again
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Dec 13, 2013, 7:56 PM EST