Dynamically loading user control

D

Divya

Hi

I am adding a user control to an aspx page dynamically. This user control has a link button. Hence I have to enclose it in a form tag with runat=server. When I execute the page, I get a javascript runtime error (; expected). The error occurs in the asp generated part of the code. The line where this error occurs is
else {theform = document._ctl0:form1;} in the following part of code

<html><head><meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"><meta name="CODE_LANGUAGE" Content="C#"><meta name="vs_defaultClientScript" content="JavaScript"><meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"><title>NMG Digital Marketing System</title><link href= ..\code\css\default.css rel='stylesheet' type='text/css'></head><body><table border="1" width="100%" height="100%"><tr><td align="center" height="20"><h3>NMG Digital Marketing System</h3></td></tr><tr><td align="center" valign="top"><form id="mainForm" runat="server" method=post><script language="javascript"
document.title = "Manage Admin"
parent.parent.parent.identifyFrame(this.name, document.title)
</script><form name="_ctl0:form1" method="post" action="index.aspx?c=admin.admincp.manageadmin" id="_ctl0_form1"><input type="hidden" name="__EVENTTARGET" value="" /><input type="hidden" name="__EVENTARGUMENT" value="" /><input type="hidden" name="__VIEWSTATE" value="dDwtOTU1NjcwNzcxO3Q8O2w8aTwxMD47PjtsPHQ8O2w8aTwwPjs+O2w8dDw7bDxpPDE+Oz47bDx0PDtsPGk8MT47PjtsPHQ8QDA8cDxwPGw8UGFnZUNvdW50O18hSXRlbUNvdW50O18hRGF0YVNvdXJjZUl0ZW1Db3VudDtEYXRhS2V5czs+O2w8aTwxPjtpPDE+O2k8MT47bDxpPDMxPjs+Oz4+Oz47Ozs7Ozs7Ozs7PjtsPGk8MD47PjtsPHQ8O2w8aTwxPjs+O2w8dDw7bDxpPDA+Oz47bDx0PHA8cDxsPFRleHQ7PjtsPDMxOz4+Oz47Oz47Pj47Pj47Pj47Pj47Pj47Pj47Pj47PkfgL7dJ8B16d6irfMFLe4UP0jBO" /><script language="javascript"><!-
function __doPostBack(eventTarget, eventArgument)
var theform
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
theform = document.forms["_ctl0:form1"]

else
theform = document._ctl0:form1

theform.__EVENTTARGET.value = eventTarget.split("$").join(":")
theform.__EVENTARGUMENT.value = eventArgument
theform.submit()

// --></script><table cellspacing="0" cellpadding="3" rules="all" border="1" id="_ctl0_dgUsers" style="height:136px;width:350px;border-collapse:collapse;"><tr><td style="font-weight:bold;">User Email Address</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td></td><td style="width:30px;"><a href="javascript:__doPostBack('_ctl0$dgUsers$_ctl2$_ctl0','')">Edit</a></td><td style="width:30px;"><a href="javascript:__doPostBack('_ctl0$dgUsers$_ctl2$_ctl1','')">Delete</a></td></tr></table></form></form></td></tr><tr><td align="center" height="20"><i>Copyright 1998 - New Media Gateway, Inc.</i></td></tr></table></body></html

I am loading the static HTML part of the above page from a template file and I am dynamically loading the user control (manageadmin.ascx)
How do I solve this problem? Could someone please help

Thanks
-Divya
 
J

John Saunders

Divya said:
Hi,

I am adding a user control to an aspx page dynamically. This user control
has a link button. Hence I have to enclose it in a form tag with
runat=server. When I execute the page, I get a javascript runtime error (;
expected). The error occurs in the asp generated part of the code. The line
where this error occurs is
else {theform = document._ctl0:form1;} in the following part of code -

<html><head><meta name="GENERATOR" Content="Microsoft Visual Studio .NET
7.1"><meta name="CODE_LANGUAGE" Content="C#"><meta
name="vs_defaultClientScript" content="JavaScript"><meta
name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5"><title>NMG Digital
Marketing System</title><link href= ..\code\css\default.css
rel='stylesheet' type='text/css'></head><body><table border="1" width="100%"
height="100%"><tr><td align="center" height="20"><h3>NMG Digital Marketing
System said:
document.title = "Manage Admin";
parent.parent.parent.identifyFrame(this.name, document.title);
</script><form name="_ctl0:form1" method="post"
action="index.aspx?c=admin.admincp.manageadmin" id="_ctl0_form1"><input
type="hidden" name="__EVENTTARGET" value="" /><input type="hidden"
name="__EVENTARGUMENT" value="" /><input type="hidden" name="__VIEWSTATE"
value="dDwtOTU1NjcwNzcxO3Q8O2w8aTwxMD47PjtsPHQ8O2w8aTwwPjs+O2w8dDw7bDxpPDE+O
z47bDx0PDtsPGk8MT47PjtsPHQ8QDA8cDxwPGw8UGFnZUNvdW50O18hSXRlbUNvdW50O18hRGF0Y
VNvdXJjZUl0ZW1Db3VudDtEYXRhS2V5czs+O2w8aTwxPjtpPDE+O2k8MT47bDxpPDMxPjs+Oz4+O
z47Ozs7Ozs7Ozs7PjtsPGk8MD47PjtsPHQ8O2w8aTwxPjs+O2w8dDw7bDxpPDA+Oz47bDx0PHA8c
DxsPFRleHQ7PjtsPDMxOz4+Oz47Oz47Pj47Pj47Pj47Pj47Pj47Pj47Pj47PkfgL7dJ8B16d6irf
MFLe4UP0jBO" /> said:
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
theform = document.forms["_ctl0:form1"];
}
else {
theform = document._ctl0:form1;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
// --></script><table cellspacing="0" cellpadding="3" rules="all"
border="1" id="_ctl0_dgUsers"
style="height:136px;width:350px;border-collapse:collapse;"><tr><td
style="font-weight:bold;">User Email
Address</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td></td><td
style="width:30px;"><a
href="javascript:__doPostBack('_ctl0$dgUsers$_ctl2$_ctl0','')">Edit</a></td>
<td style="width:30px;"><a
href="javascript:__doPostBack('_ctl0$dgUsers$_ctl2$_ctl1','')">Delete</a></t
d></tr></table></form></form></td></tr><tr><td align="center"
height="20"> said:
I am loading the static HTML part of the above page from a template file
and I am dynamically loading the user control (manageadmin.ascx).
How do I solve this problem? Could someone please help?

This is a known problem in ASP.NET 1.1. There is a patch, but I'm afraid
I've misplaced the number of the KB article.
 
J

John Saunders

Divya said:
Hi John,

Thanks for the tip. I looked up the KB article and contacted Microsoft
about this, got the fix, installed it and it executed fine. But now, I seem
to have another problem. I am guessing that it is due to the patch (for
..Net) that I installed. I have an aspx page dynamically loading a user
control. The user control has a datagrid with a column of 'edit' link
buttons. When the user clicks on one of the edit buttons, I want to redirect
to another aspx page with the itemIndex of the row (that was clicked), sent
as a query string.
When I execute this and click an edit button link in the datagrid, it
throws a javascript runtime error -
'__EVENTTARGET' is null or not an object.
In the source, it points to the line -
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");

Divya, I didn't see this problem after applying the patch. However:
....
Below is the entire source (generated by .Net) of the page when the error occurs -

<html><head><meta name="GENERATOR" Content="Microsoft Visual Studio .NET
7.1"><meta name="CODE_LANGUAGE" Content="C#"><meta
name="vs_defaultClientScript" content="JavaScript"><meta
name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5"><title>NMG Digital
Marketing System</title><link href= ..\code\css\default.css
rel='stylesheet' type='text/css'></head><body><table border="1" width="100%"
height="100%"><tr><td align="center" height="20"><h3>NMG Digital Marketing
System</h3></td></tr><tr><td align="center" valign="top"><form id="mainForm"
runat="server" method=post><form name="__aspnetForm" method="post"
action="index.aspx?c=test" id="__aspnetForm">

I notice that you have a form called "mainForm". You should find a way to do
without it. There should only be one form on the page, as far as ASP.NET is
concerned. At the very least you should check to see if the same problem
happens on a page without the nested forms.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top