I have just started learning the ins and outs of ASP.Net and am running Web Matrix while getting to grips with the formatting etc.
My problem is that any time i add a textbox webcontrol to a page, instead of displaying the actual textbox I get an 'Error Rendering Control' box stating that 'RegisterForEventValidation can only be called during Render()'!!!
I am at a loss as to why this is happening, which isn't just restricted to the textbox webcontrol but ALL the control's available except the Label & Literal webcontrols which seem to behave properly.
Could someone please please please provide some guidance for this newbie to ASP.Net in order that I can keep the current enthusiasm going to learn.
The compilation error points to line 5 of the code and states ---> "Compiler Error Message: BC30456: 'Value' is not a member of 'System.Web.UI.WebControls.TextBox'."
If you want to get a value to the textbox you are not able to do it in the page_load event. You can set the time in the Page_PreRender event. It is the exact same as the page_load syntax you just put Page_PreRender. It happens after the page_load event.
In the Page_load event the textbox does not exist yet.
Also just looking at it. You are using Textbox.Value = It should be Textbox.Text. And to convert the time to a string use the Convert.ToString method. This is a c# method. I don't use visual basic and never have so I don't know the syntax for it. But you may
have to cast you time to a string I don't know for sure with visual basic. If you are learning you may want to think of learning c#. Alot of programmers have to learn c# a couple of years after visual as it is a better language with more features.
Wrong on booth things, the controls are available on page load, and c# and vb have the same features, main difference is syntax. However it's good to learn both as they are both used widely across
industries. <:o:p>
Thanks guys, the changing the property to Text instead of Value worked but my (other) main issue is in the web matrix design screen when I try to add a web control fro the toolbox. When I place the textbox on the design pane I get the following :
"Error Rendering Control - currentDT An unhandled exception has occured. RegisterForEventValidation can only be called during Render()"
As a newbie to this it might be a minor annoyance to others but I was expecting an actual text box to be displayed.
Any explanation/help on this would be greatly appreciated.
Right if you want to correct me. The textbox is created in the pageload event. So if you want to insert data into the textbox programmatically in the page_load event this often causes errors. i.e the error message with this can only be done in the render
event.
Secondly there are more features with c#. ie. operator overloading, alot more error catching features and there are more. I don't get why someone would correct me if they don't know for certain.
MasterToad
0 Points
4 Posts
RE : Beginners Nightmare .... PLEASE help
Sep 22, 2010 10:44 AM|LINK
I have just started learning the ins and outs of ASP.Net and am running Web Matrix while getting to grips with the formatting etc.
My problem is that any time i add a textbox webcontrol to a page, instead of displaying the actual textbox I get an 'Error Rendering Control' box stating that 'RegisterForEventValidation can only be called during Render()'!!!
I am at a loss as to why this is happening, which isn't just restricted to the textbox webcontrol but ALL the control's available except the Label & Literal webcontrols which seem to behave properly.
Could someone please please please provide some guidance for this newbie to ASP.Net in order that I can keep the current enthusiasm going to learn.
Thanks so much in advance
cookie_power...
Member
229 Points
122 Posts
Re: RE : Beginners Nightmare .... PLEASE help
Sep 22, 2010 10:58 AM|LINK
Could you post your code, will be easier to debug
seamus1982
Participant
936 Points
375 Posts
Re: RE : Beginners Nightmare .... PLEASE help
Sep 22, 2010 11:00 AM|LINK
Hi,
Can you provide some of you code so I can take a look at it.
MasterToad
0 Points
4 Posts
Re: RE : Beginners Nightmare .... PLEASE help
Sep 22, 2010 11:11 AM|LINK
Hi the code is pasted below, VERY simple piece of code to place the current date & time into a textbox webcontrol.
The error originates on the actual webcontrol object when i place it in design view from the toolbox.
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
currentDT.Value = DateTime.Now
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:TextBox id="currentDT" runat="server"></asp:TextBox>
<!-- Insert content here -->
</form>
</body>
</html>
The compilation error points to line 5 of the code and states ---> "Compiler Error Message: BC30456: 'Value' is not a member of 'System.Web.UI.WebControls.TextBox'."
seamus1982
Participant
936 Points
375 Posts
Re: RE : Beginners Nightmare .... PLEASE help
Sep 22, 2010 11:17 AM|LINK
If you want to get a value to the textbox you are not able to do it in the page_load event. You can set the time in the Page_PreRender event. It is the exact same as the page_load syntax you just put Page_PreRender. It happens after the page_load event. In the Page_load event the textbox does not exist yet.
cookie_power...
Member
229 Points
122 Posts
Re: RE : Beginners Nightmare .... PLEASE help
Sep 22, 2010 11:18 AM|LINK
change:
currentDT.Value = DateTime.Now
to
currentDT.Text = DateTime.Now
seamus1982
Participant
936 Points
375 Posts
Re: RE : Beginners Nightmare .... PLEASE help
Sep 22, 2010 11:20 AM|LINK
Also just looking at it. You are using Textbox.Value = It should be Textbox.Text. And to convert the time to a string use the Convert.ToString method. This is a c# method. I don't use visual basic and never have so I don't know the syntax for it. But you may have to cast you time to a string I don't know for sure with visual basic. If you are learning you may want to think of learning c#. Alot of programmers have to learn c# a couple of years after visual as it is a better language with more features.
cookie_power...
Member
229 Points
122 Posts
Re: RE : Beginners Nightmare .... PLEASE help
Sep 22, 2010 11:25 AM|LINK
Hi seamus1982,
Wrong on booth things, the controls are available on page load, and c# and vb have the same features, main difference is syntax. However it's good to learn both as they are both used widely across industries. <:o:p>
MasterToad
0 Points
4 Posts
Re: RE : Beginners Nightmare .... PLEASE help
Sep 22, 2010 11:33 AM|LINK
Thanks guys, the changing the property to Text instead of Value worked but my (other) main issue is in the web matrix design screen when I try to add a web control fro the toolbox. When I place the textbox on the design pane I get the following :
"Error Rendering Control - currentDT An unhandled exception has occured. RegisterForEventValidation can only be called during Render()"
As a newbie to this it might be a minor annoyance to others but I was expecting an actual text box to be displayed.
Any explanation/help on this would be greatly appreciated.
Thanks again for helping me out with the code :)
seamus1982
Participant
936 Points
375 Posts
Re: RE : Beginners Nightmare .... PLEASE help
Sep 22, 2010 11:33 AM|LINK
Right if you want to correct me. The textbox is created in the pageload event. So if you want to insert data into the textbox programmatically in the page_load event this often causes errors. i.e the error message with this can only be done in the render event.
Secondly there are more features with c#. ie. operator overloading, alot more error catching features and there are more. I don't get why someone would correct me if they don't know for certain.