Johny Bravo
asked on
Updatepanels and user controls
<asp:UpdatePanel ID="uptPnlMain" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<table>
<tr style="padding-top: 7px">
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tab">
<div>
<tr>
<td width="979" align="left" valign="middle" class="pnav" style="padding-left: 15px;
padding-top: 5px; padding-right: 4px;">
<asp:LinkButton ID="lnkCorporate" runat="server" CausesValidation="false"
OnCommand="lnkCorporate_Co mmand" Text="Corp ID |"></asp:LinkButton>
<asp:LinkButton ID="lnkPersonal" runat="server" CausesValidation="false"
OnCommand="lnkPersonal_Com mand" Text="Personal |"></asp:LinkButton>
						 </td>
</tr>
</div>
</table>
			 <tr id="trCorporateRow" visible="false" runat="server">
<td>
<ucCorporate:CorpId ID="CorpIdTab" runat="server" />
</td>
</tr>
<tr id="trPersonalRow" visible="false" runat="server">
<td>
<ucPersonal:Personal ID="PersonalTab" runat="server" />
</td>
</tr>
protected void lnkCorporate_Command(objec t sender, EventArgs e)
{
		trPersonalRow.Visi ble = true;
trCorporateRow.Visible = false;
	}
protected void lnkPersonal_Command(object sender, EventArgs e)
{
		trPersonalRow.Visi ble = false;
trCorporateRow.Visible = true;
	}
There are two user controls,personal and corporate.
I have noticed one thing.By default I am loading Personal user control.
When I click corporate link,corporate user control is loaded.
but html is not changed.In the source I am having controls of personal tab only.
I tried using placeholder instead of using rows but sane thing happens.
I am assuming this is because of the Updatepanel,as before it was loading controls of the respective user control.
I am expecting some guidance from you experts.Please tell me what needs to be done?
<ContentTemplate>
<table>
<tr style="padding-top: 7px">
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tab">
<div>
<tr>
<td width="979" align="left" valign="middle" class="pnav" style="padding-left: 15px;
padding-top: 5px; padding-right: 4px;">
<asp:LinkButton ID="lnkCorporate" runat="server" CausesValidation="false"
OnCommand="lnkCorporate_Co
<asp:LinkButton ID="lnkPersonal" runat="server" CausesValidation="false"
OnCommand="lnkPersonal_Com
						 </td>
</tr>
</div>
</table>
			 <tr id="trCorporateRow" visible="false" runat="server">
<td>
<ucCorporate:CorpId ID="CorpIdTab" runat="server" />
</td>
</tr>
<tr id="trPersonalRow" visible="false" runat="server">
<td>
<ucPersonal:Personal ID="PersonalTab" runat="server" />
</td>
</tr>
protected void lnkCorporate_Command(objec
{
		trPersonalRow.Visi
trCorporateRow.Visible = false;
	}
protected void lnkPersonal_Command(object
{
		trPersonalRow.Visi
trCorporateRow.Visible = true;
	}
There are two user controls,personal and corporate.
I have noticed one thing.By default I am loading Personal user control.
When I click corporate link,corporate user control is loaded.
but html is not changed.In the source I am having controls of personal tab only.
I tried using placeholder instead of using rows but sane thing happens.
I am assuming this is because of the Updatepanel,as before it was loading controls of the respective user control.
I am expecting some guidance from you experts.Please tell me what needs to be done?
Did you tried to hide or show controls not rows in a table ?
or u can put it in a div if more than one controls and do the hide and show.
ASKER
Not tried earlier,
but after your suggestion I tried putting
PersonalTab.Visible = true;
CorpIdTab.Visible = false;
but html is not changing.
but after your suggestion I tried putting
PersonalTab.Visible = true;
CorpIdTab.Visible = false;
but html is not changing.
ASKER
Controls are loaded.I can see the controls on the page.but when I see the source of that page,the controls are not present in the source
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I tried uptPnlMain.Update() with no effect.
I need the changed html as I have to write some javasript functions there.
But when I write any,in document.getElementById i never found the control
I need the changed html as I have to write some javasript functions there.
But when I write any,in document.getElementById i never found the control
But do you see it in the UI?
ASKER
Yes in UI it is appearing but not when I look for the source
ASKER
Yes in UI it is appearing but not when I look for the source
You probably have the same problem as here: http://stackoverflow.com/questions/1570540/getting-dynamically-generated-html-controls-when-using-updatepanel
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Okk.
but when I write a javascript function on the controls on second user control,it's not working.
As I am not getting that control,what should I do then?
but when I write a javascript function on the controls on second user control,it's not working.
As I am not getting that control,what should I do then?
Could you clarify "not working" a little? What isn't working, what is your javascript attempting to do?
They have probably different names because of the injection then you are expecting in your JS.
ASKER
I have checkbox in the second user control which copies current address to permanent address.
When I click the checkbox,I get "Error: Object expected" for javascript.
I put debugger in the function,but it is not reached even.
Without updatepanel,it works fine
Following is the javascript function.
When I click the checkbox,I get "Error: Object expected" for javascript.
I put debugger in the function,but it is not reached even.
Without updatepanel,it works fine
Following is the javascript function.
function FillPermanent()
{
if(document.getElementById('chkCopy').checked)
{
var IndexValue = $get('<%=ddlLocalCountry.ClientID %>').selectedIndex;
var SelectedVal = $get('<%=ddlLocalCountry.ClientID %>').options[IndexValue].value;
var IndexValue1 = $get('<%=ddlLocalState.ClientID %>').selectedIndex;
var SelectedVal1 = $get('<%=ddlLocalState.ClientID %>').options[IndexValue1].value;
var IndexValue2 = $get('<%=ddlLocalCity.ClientID %>').selectedIndex;
var SelectedVal2 = $get('<%=ddlLocalCity.ClientID %>').options[IndexValue2].value;
document.getElementById('<%=txtPermArea.ClientID %>').value = document.getElementById('<%= txtLocalArea.ClientID %>').value;
document.getElementById('<%=txtPermSubUrb.ClientID %>').value = document.getElementById('<%=txtLocalSubUrb.ClientID %>').value ;
document.getElementById('<%=txtPermPIN.ClientID %>').value = document.getElementById('<%=txtLocalPIN.ClientID %>').value ;
var behavior = $find('<%=CDDPermCountry.ClientID %>');
behavior.set_SelectedValue(SelectedVal);
behavior._onParentChange(null, true);
var behavior1 = $find('<%=CCDPermState.ClientID %>');
behavior1.set_SelectedValue(SelectedVal1);
behavior1._onParentChange(null, true);
var behavior2 = $find('<%=CDDPermCity.ClientID %>');
behavior2.set_SelectedValue(SelectedVal2);
behavior2._onParentChange(null, true);
}
If 'chkCopy' as an ASP.NET Checkbox it will have a different id, so it will return null. You will also need the ClientID from the checkbox in that case.
ASKER
<input type="checkbox" id="chkCopy" name="chkCopy" onclick="FillPermanent()" />
It's an html control
It's an html control
Try changing the start of your javascript to:
function FillPermanent( source )
{
if(source.checked)
{
And your checkbox to:
<input type="checkbox" id="chkCopy" name="chkCopy" onclick="FillPermanent(thi s);" />
function FillPermanent( source )
{
if(source.checked)
{
And your checkbox to:
<input type="checkbox" id="chkCopy" name="chkCopy" onclick="FillPermanent(thi
ASKER
:( this is also not working.
Currently I have removed updatepanel and it is working fine.I am waiting from some solution.thanks
Currently I have removed updatepanel and it is working fine.I am waiting from some solution.thanks
Try changing the LinkButton event to OnClick. If that doesn't work try adding also adding Triggers to the UpdatePanel.
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lnkCorporate" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="lnkPersonal" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</asp:Panel>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lnkCorporate" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="lnkPersonal" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</asp:Panel>
ASKER
Thanks Experts