Results 1 to 12 of 12

Thread: JS Error

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    JS Error

    My form is not able to load,getting the error-
    Code:
    The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
    Code:
    var _HiddenLicenseRate = document.getElementById('<%= HiddenLicenseRate.ClientID %>');
    For the alternative,I searched the Net
    Code:
     function GetDGHLicenseFees() {
               alert('GetDGHLicenseFees');
               var _HiddenLicenseRate = document.getElementById('<# 
    HiddenLicenseRate.ClientID %>');
               alert(_TxtDGH_Acreage);
    }
    Code:
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                TxtDGH_Acreage.Attributes.Add("onKeyUp", "GetDGHLicenseFees();"); 
    }
    }


    If I used the above code,Now my form is able to load atleats,but when the procedure GetDGHLicenseFees is called,then in _TxtDGH_Acreage is null.

    Wat to do?? I m unabel to find the solution & nt getting y the error is coming???

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: JS Error

    Hey,

    Where is _TxtDGH_Acreage defined? I don't see that in the code that you have posted?

    It would also be useful to see the actual JavaScript that is rendered to the page.

    Gary

  3. #3
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: JS Error

    I was getting that error the other day and it was because I had runat="server' in the header. Not sure why that caused an issue but it did.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  4. #4

  5. #5
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: JS Error

    Quote Originally Posted by gep13 View Post
    In the header of what Sean?
    Because I was using Themes I had some error telling me to add the runat to the head block, e.g.

    <head runat="server">

    That seemed to then cause for me the other error he was seeing. I honestly wasn't using anything in my Theme but the CSS file so I just included that and ditched the themes.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Re: JS Error

    hi help me out!!!! There is another method to get the clientID in New Popup WIndow.
    I have open window with the foll. code-
    Code:
     protected void Button2_Click(object sender, EventArgs e)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("<script language='javascript'>");
            sb.Append("window.open('Practise.aspx');");
            sb.Append("</script>");
            Type t = this.GetType();
            if (!ClientScript.IsClientScriptBlockRegistered(t, "PopupScript"))
                ClientScript.RegisterClientScriptBlock(t, "PopupScript", sb.ToString());
        }
    New WIndow code-
    Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
        <script language ="javascript" type ="text/javascript" >
          function GetDGHLicenseFees() {
               alert('GetDGHLicenseFees');
               var TxtDGH_Acreage1= document.getElementById('<#TxtDGH_Acreage.ClientID&#37;>');
               alert(TxtDGH_Acreage1);
               alert(TxtDGH_Acreage1.value);
               alert('a');
               }
        </script>
    </head>
    
    Call JS--- protected void Page_Load(object sender, EventArgs e)
        {
            TxtDGH_Acreage.Attributes.Add("onKeyUp", "GetDGHLicenseFees();");
        }
    OUTPUT ---
    New WIndow is opened,When I type in textbox TxtDGH_Acreage, then i get the alert GetDGHLicenseFees,then i get the alert null. I m not able to find why it is comg null.

    SOURCE CODE OF MY NEW WINDOW-
    Code:
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>
    	Untitled Page
    </title>
        <script language ="javascript" type ="text/javascript" >
          function GetDGHLicenseFees() {
               alert('GetDGHLicenseFees');
               var TxtDGH_Acreage1= document.getElementById('<#TxtDGH_Acreage.ClientID%>');
               alert(TxtDGH_Acreage1);
               alert(TxtDGH_Acreage1.value);
               alert('a');
               }
        </script>
    </head>
    <body>
        <form name="form1" method="post" action="Practise.aspx" id="form1">
    <div>
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNDIwOTg2MDQ1D2QWAgIDD2QWAgIDDw9kFgIeB29uS2V5VXAFFEdldERHSExpY2Vuc2VGZWVzKCk7ZGRcsXd3fXpXC62TPUsYrtIE/J7Shg==" />
    </div>
    
    <div>
    
    	<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwLx1saXBAL5gcfVDwLs0fbZDNixK+gMjKE/JW0yXOPLICXP8ZWk" />
    </div>
        <div>
        
            <span id="Label1">Practise</span>
        
            <input name="TxtDGH_Acreage" type="text" id="TxtDGH_Acreage" onKeyUp="GetDGHLicenseFees();" />
            <input name="TextBox2" type="text" id="TextBox2" />
        
        </div>
        </form>
    </body>
    </html>

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: JS Error

    Hey,

    In this line:

    Code:
    var TxtDGH_Acreage1= document.getElementById('<#TxtDGH_Acreage.ClientID&#37;>');
    You have an error. You have a malformed ASP.Net Server Tag, hence, the ASP.Net Engine is not parsing the tag, and replacing it with the ClientID of the control that you want.

    Change it to:

    Code:
    var TxtDGH_Acreage1= document.getElementById('<%#TxtDGH_Acreage.ClientID%>');
    Gary

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Re: JS Error

    Hi Gep sir,Still Not working.STill I m getting null.Even you can see Source code line marked as red. See the diff. b/w source codes dat i paste above & Here.

    SOURCE CODE-
    Code:
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>
    	Untitled Page
    </title>
        <script language ="javascript" type ="text/javascript" >
          function GetDGHLicenseFees() {
               alert('GetDGHLicenseFees');
               var TxtDGH_Acreage1= document.getElementById('');         
      alert(TxtDGH_Acreage1);
               alert(TxtDGH_Acreage1.value);
               alert('a');
               }
        </script>
    </head>
    <body>
        <form name="form1" method="post" action="Practise.aspx" id="form1">
    <div>
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTEyNTc0ODY4OTkPZBYCAgMPZBYCAgMPD2QWAh4Hb25LZXlVcAUUR2V0REdITGljZW5zZUZlZXMoKTtkZDtxTb9JunXzUQWYFl0DWvV4TRtm" />
    </div>
    
    <div>
    
    	<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwLytMu9BAL5gcfVDwLs0fbZDFw7XnFbi+eKZxp7n4wwndDLCZkF" />
    </div>
        <div>
        
            <span id="Label1">Practise</span>
        
            <input name="TxtDGH_Acreage" type="text" id="TxtDGH_Acreage" onKeyUp="GetDGHLicenseFees();" />
            <input name="TextBox2" type="text" id="TextBox2" />
        
        </div>
        </form>
    </body>
    </html>

    Code:
    function GetDGHLicenseFees() {
               alert('GetDGHLicenseFees');
               var TxtDGH_Acreage1= document.getElementById('<&#37;#TxtDGH_Acreage.ClientID%>');
               alert(TxtDGH_Acreage1);
               alert(TxtDGH_Acreage1.value);
               alert('a');
               }
        </script>

  9. #9
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: JS Error

    Hey,

    The only reason that you would get this:

    Code:
    var TxtDGH_Acreage1= document.getElementById('');
    Is if that variable resolved to an empty string. Where is that control declared? On the page that you are opening, or on the page that you are opening from?

    Gary

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Re: JS Error

    On the Page i m opening(on New pop up WIndow) !!!

  11. #11
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: JS Error

    Quote Originally Posted by sonia.sardana View Post
    On the Page i m opening(on New pop up WIndow) !!!
    If you are opening a popup during the page load event, then the script should be at the end the page ( before form closing tag). Then only you can able to access the controls in that page.

    As the Controls won't be created during the page load event, you will get null for this event.

    Code:
     var TxtDGH_Acreage1= document.getElementById('');
    Please mark you thread resolved using the Thread Tools as shown

  12. #12
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: JS Error

    sonia.sardana, you might want to think about registering the JavaScript for your PopUp Window in the same way that you have done the parent page.

    Gary

Posting Permissions

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



Click Here to Expand Forum to Full Width