Description:
An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1002: ; expected Source Error:
Line 330: #line default
Line 331: #line hidden
Line 332: @__w.Write("\').value = t;\r\n alert(t);\r\n } \r\n</script>\r\n"); Line 333: parameterContainer.Controls[0].RenderControl(@__w);
Line 334: @__w.Write(" \r\n ");
<script type="text/javascript">
function buildArgument(sender, args) {
var t = "K";
document.getElementById('<%=argument.ClientID%>').value = t;
}
</script>
You can also try doing it using jQuery ..
// You can also accomplish this using jQuery...
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:HiddenField ID="argument" runat="server" />
<asp:Button ID="SelectButton" runat="server" Text="Select" Width="100px" />
<script type="text/javascript">
S(function() {
$('[id*=SelectButton]').on('click', function(){
var t = "K";
$('[id*=argument]').val(t);
});
}
</script>
JohnKainn
Member
26 Points
31 Posts
Unable to set value of the property 'value': object is null or undefined - webusercontrol
Jul 08, 2012 01:34 PM|LINK
Hello,
I add a web user control to an aspx page. It is the only thing that is on the aspx page.
Here is the code on the web user control
<script type="text/javascript"> function buildArgument(sender, args) { var t = "K"; document.getElementById("argument").value = t; } </script><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:HiddenField ID="argument" runat="server" /> <asp:Button ID="SelectButton" runat="server" Text="Select" Width="100px" OnClientClick="buildArgument(this, event);" />When I click the "SelectButton" I get the following error:
Microsoft JScript runtime error: Unable to set value of the property 'value': object is null or undefined In the debugger this gets highlighted:
document.getElementById("argument").value = t;If I do not use web user control, but put this code to an aspx page then I do not get this error when I click the button.
Why is this and what can I do to fix this?
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Unable to set value of the property 'value': object is null or undefined - webusercontrol
Jul 08, 2012 02:11 PM|LINK
try this
document.getElementById('<% argument.ClientID %>').value = t;Ruchira
All-Star
44181 Points
7179 Posts
MVP
Re: Unable to set value of the property 'value': object is null or undefined - webusercontrol
Jul 08, 2012 05:03 PM|LINK
Hello,
This should be correct as,
document.getElementById('<%=argument.ClientID%>').value = t;
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.JohnKainn
Member
26 Points
31 Posts
Re: Unable to set value of the property 'value': object is null or undefined - webusercontrol
Jul 08, 2012 07:20 PM|LINK
I tried this, but then I get this error:
1) Invalid expression term'.' 2) ;expected - It points to App_Web_fgztsflt8.cs
@__w.Write( "\').value = t;\r\n document.getElementById(\"argument\").value = t;\r\n } \r\n</" + "script>\r\n");
JohnKainn
Member
26 Points
31 Posts
Re: Unable to set value of the property 'value': object is null or undefined - webusercontrol
Jul 10, 2012 10:18 AM|LINK
I found how to do this. If I set the HiddenField: ClientIdMode="Static" then it works.
abdheshtech
Member
99 Points
32 Posts
Re: Unable to set value of the property 'value': object is null or undefined - webusercontrol
Jul 10, 2012 12:16 PM|LINK
check it.
<script type="text/javascript">
function buildArgument(sender, args) {
var t = "K";
document.getElementById('<% argument.ClientID %>').value = t;
}
</script>
javascript: C#.net
Web Developer
JohnKainn
Member
26 Points
31 Posts
Re: Unable to set value of the property 'value': object is null or undefined - webusercontrol
Jul 10, 2012 05:59 PM|LINK
Then I get this error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1002: ; expected
Source Error:
Line 330: #line default Line 331: #line hidden Line 332: @__w.Write("\').value = t;\r\n alert(t);\r\n } \r\n</script>\r\n"); Line 333: parameterContainer.Controls[0].RenderControl(@__w); Line 334: @__w.Write(" \r\n ");javascript: C#.net
sushanth009
Contributor
6243 Points
1168 Posts
Re: Unable to set value of the property 'value': object is null or undefined - webusercontrol
Jul 10, 2012 09:06 PM|LINK
try this
<script type="text/javascript"> function buildArgument(sender, args) { var t = "K"; document.getElementById('<%=argument.ClientID%>').value = t; } </script>You can also try doing it using jQuery ..
// You can also accomplish this using jQuery... <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:HiddenField ID="argument" runat="server" /> <asp:Button ID="SelectButton" runat="server" Text="Select" Width="100px" /> <script type="text/javascript"> S(function() { $('[id*=SelectButton]').on('click', function(){ var t = "K"; $('[id*=argument]').val(t); }); } </script>JohnKainn
Member
26 Points
31 Posts
Re: Unable to set value of the property 'value': object is null or undefined - webusercontrol
Jul 10, 2012 10:21 PM|LINK
Thank you. Now the error is gone. In Page_Init I want to get the value of argument.
This is how I do it:
protected void Page_Init(object sender, EventArgs e) { string arg = Request.Form["argument"]; }If I do this in aspx.cs I get the value of argument. If it is in ascx.cs the value is null.
The code is exactly the same in aspx and the web user control.
How can I get the value of the argument in page_init in ascx.cs?
roopeshreddy
All-Star
20259 Points
3345 Posts
Re: Unable to set value of the property 'value': object is null or undefined - webusercontrol
Jul 11, 2012 05:52 AM|LINK
Hi,
It's working as it supposed to work! Since you are accessing the Form data, where, the <form> won't be available in User Controls(.ascx)!
It's working fine in .aspx.cs file, since it has <form> tag in it!
Hope it helps u...
Roopesh Reddy C
Roopesh's Space