|
-
May 19th, 2010, 11:52 AM
#1
Thread Starter
Hyperactive Member
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???
-
May 19th, 2010, 11:55 AM
#2
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
-
May 19th, 2010, 01:04 PM
#3
Frenzied Member
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.
-
May 19th, 2010, 02:49 PM
#4
Re: JS Error
In the header of what Sean?
-
May 19th, 2010, 03:35 PM
#5
Frenzied Member
Re: JS Error
 Originally Posted by gep13
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.
-
May 23rd, 2010, 11:59 AM
#6
Thread Starter
Hyperactive Member
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%>');
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>
-
May 23rd, 2010, 12:02 PM
#7
Re: JS Error
Hey,
In this line:
Code:
var TxtDGH_Acreage1= document.getElementById('<#TxtDGH_Acreage.ClientID%>');
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
-
May 23rd, 2010, 12:42 PM
#8
Thread Starter
Hyperactive Member
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('<%#TxtDGH_Acreage.ClientID%>');
alert(TxtDGH_Acreage1);
alert(TxtDGH_Acreage1.value);
alert('a');
}
</script>
-
May 23rd, 2010, 01:24 PM
#9
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
-
May 23rd, 2010, 02:24 PM
#10
Thread Starter
Hyperactive Member
Re: JS Error
On the Page i m opening(on New pop up WIndow) !!!
-
May 24th, 2010, 12:46 AM
#11
Re: JS Error
 Originally Posted by sonia.sardana
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
-
May 24th, 2010, 01:36 AM
#12
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|