Dynamically loading user control

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Dynamically loading user control

    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="dDwtOTU1NjcwNzcxO3Q8O2w8aTwxMD47PjtsPHQ8O2w 8aTwwPjs+O2w8dDw7bDxpPDE+Oz47bDx0PDtsPGk8MT47PjtsP HQ8QDA8cDxwPGw8UGFnZUNvdW50O18hSXRlbUNvdW50O18hRGF 0YVNvdXJjZUl0ZW1Db3VudDtEYXRhS2V5czs+O2w8aTwxPjtpP DE+O2k8MT47bDxpPDMxPjs+Oz4+Oz47Ozs7Ozs7Ozs7PjtsPGk 8MD47PjtsPHQ8O2w8aTwxPjs+O2w8dDw7bDxpPDA+Oz47bDx0P HA8cDxsPFRleHQ7PjtsPDMxOz4+Oz47Oz47Pj47Pj47Pj47Pj4 7Pj47Pj47Pj47PkfgL7dJ8B16d6irfMFLe4UP0jBO" /><script language="javascript"><!-
    function __doPostBack(eventTarget, eventArgument)
    var theform
    if (window.navigator.appName.toLowerCase().indexOf("n etscape") > -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
    Divya Guest

  2. Similar Questions and Discussions

    1. Dynamically Loading User Control in PlaceHolder
      Hi , I load dynamically a user control in PlaceHolder with the number of fileds in db. When loading user control there is no problem, if returning...
    2. Dynamically loading user control into Placeholder gives Object reference not set to an instance of an object
      I've created user controls that contain listboxes that are dynamically populated from the database. In the html view of the user control...
    3. Dynamically Adding User Control with Child User Control
      I have a user control that has a child user control. If I drag this onto the page, it appears and functions normally. If I attempt to add the...
    4. How do I dynamically add a user control to a web page?
      I have a user control which I created that does not work when I add it dynamically to a web page. My code looks like this. For x = 0 to max...
    5. Loading/Unloading web user controls dynamically in code - Does this look right?
      You ought to check out the DynamicPlaceHolder control instead of using the builtin Placeholder. ...
  3. #2

    Default Re: Dynamically loading user control

    "Divya" <divyas@newmediagateway.com> wrote in message
    news:0C991F55-DCC2-4784-991F-644765DEB5EC@microsoft.com...
    > 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="dDwtOTU1NjcwNzcxO3Q8O2w8aTwxMD47PjtsPHQ8O2w 8aTwwPjs+O2w8dDw7bDxpPDE+O
    z47bDx0PDtsPGk8MT47PjtsPHQ8QDA8cDxwPGw8UGFnZUNvdW5 0O18hSXRlbUNvdW50O18hRGF0Y
    VNvdXJjZUl0ZW1Db3VudDtEYXRhS2V5czs+O2w8aTwxPjtpPDE +O2k8MT47bDxpPDMxPjs+Oz4+O
    z47Ozs7Ozs7Ozs7PjtsPGk8MD47PjtsPHQ8O2w8aTwxPjs+O2w 8dDw7bDxpPDA+Oz47bDx0PHA8c
    DxsPFRleHQ7PjtsPDMxOz4+Oz47Oz47Pj47Pj47Pj47Pj47Pj4 7Pj47Pj47PkfgL7dJ8B16d6irf
    MFLe4UP0jBO" /><script language="javascript"><!--
    > function __doPostBack(eventTarget, eventArgument) {
    > var theform;
    > if (window.navigator.appName.toLowerCase().indexOf("n etscape") > -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"><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?
    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.
    --
    John Saunders
    johnwsaundersiii at hotmail


    John Saunders Guest

  4. #3

    Default Re: Dynamically loading user control

    "Divya" <divyas@newmediagateway.com> wrote in message
    news:53A39787-78FF-40C0-9F0B-593C48E15EB4@microsoft.com...
    > 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.
    --
    John Saunders
    johnwsaundersiii at hotmail


    John Saunders Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139