Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Sep 22, 2010 10:44 PM by simtan
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
Sep 22, 2010 10:58 AM|LINK
Could you post your code, will be easier to debug
Sep 22, 2010 11:00 AM|LINK
Can you provide some of you code so I can take a look at it.
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" %>
Sub Page_Load(sender as Object, e as EventArgs)
currentDT.Value = DateTime.Now
<asp:TextBox id="currentDT" runat="server"></asp:TextBox>
<!-- Insert content here -->
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'."
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.
Sep 22, 2010 11:18 AM|LINK
currentDT.Value = DateTime.Now
currentDT.Text = DateTime.Now
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.
Sep 22, 2010 11:25 AM|LINK
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
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 :)
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
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.