Intellisense indicates that form doesn't exist - c#

I opted to copy my web code from one page different page just because it made more sense in the scheme of things to have it be the 'Default.aspx' page. I figured no biggie... copy all but the top line and make some minor alterations to the aspx page then copy all of the aspx.cs page and should be golden.
Wasn't that clean to my surprise!
First had to redefine my sql connections (not a big deal).
But the thing that really has be in a bit of a quandary is Intellisense has gone stupid on me regarding the FormView used on the page.
<asp:FormView runat="server" ID="ARS30InputFrm" DataSourceID="ARFS" DefaultMode="Insert">
This is clearly in my aspx page. Data source works all should be fine. But I have an error over on the aspx.cs where I redline on the form name on line three here and the help indicates that it doesn't exist!
protected void ARSControlNumTextBox_TextChanged(object sender, EventArgs e)
{
TextBox thecontrol = (TextBox)ARS30InputFrm.Row.FindControl("ARSControlNumTextBox");
if (thecontrol != null)
Session["CCtrl"] = thecontrol.Text;
}
ie: TextBox thecontrol = (TextBox).... ARS30InputFrm .... is where the error flags.
Any idea's on how to clear this issue? I've tried rebuilding, reloading, but nothing seems to work. This clearly is the name of the form!

Well this is not an answer to 'WHY' intelisense went wacko, but I was able to solve the issue by blowing away the aspx and aspx.cs and recreating them as I had done before (about 3 minutes of copy work) and it worked straight up!
It simply must have been something in VS that was glitchy and didn't go down right the first time through. The second time was a charm.
Live and learn...

Related

Visual Studio 2008 can't recognize control(in webform page) in partial class

I insert a Textbox control in webform page,but I can't find it in partial class when I use it like this.txtPaySerialNumber.Text,It looks like I had not insert that in webform page.
The old control I had inserted had no problem. I have develop web form a year, this crazy thing happened only in vs2008.(My OS is Windows 8 64).
It's not exactly clear without an example of your scenario, but a couple of things to check....
Make sure you're control is defined in the page (and properly, check the error view for bad markup declarations, etc.):
<asp:TextBox runat="server" ID="PaySerialNumber />
You'll likely noticed I summarily abandoned the awful Hungarian Notation.
Then in the code-behind, access it (omitting the double this prefix (which I'm not sure whether to take literally from your post or not):
PaySerialNumber.Text = "some text";
If that fails, try it in the markup file itself:
<script runat="server" language="CSharp">
void Page_Load(object sender, EventArgs e) {
PaySerialNumber.Text = "some text";
}
</script>
If that works, then you likely have a mismatched page declaration, so it's not pointing to the right code-behind file.
If all else fails and the page, code-behind, or whatever, still isn't seeing the thing, then try a "clean solution and then "rebuild"; perhaps even restarting VS to reload the project after a clean.
If it still isn't working, then we need more information.

Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server."

I have couple of update panels and jquery tabs on page. And also I am loading couple user controls on update panels. After user waited for couple of minutes (not checked the time approx 40 mins). when user send request from submit button it is giving below error?
'Sys.WebForms.PageRequestManagerServerErrorException:
Sys.WebForms.PageRequestManagerServerErrorException: An unknown
error occurred while processing the request on the server. The status
code returned from the server was: 0' when calling method:
[nsIDOMEventListener::handleEvent]
I am not able trace this issue to fix. But I am sure. This is causing by Ajax. Gurus, if you knows solution. Please let me know.
This issue sometimes occurs when you have a control registered as an AsyncPostbackTrigger in multiple update panels.
If that's not the problem, try adding the following right after the script manager declaration, which I found in this post by manowar83, which copies and slightly modifies this post by larryw:
<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args){
if (args.get_error() != undefined){
args.set_errorHandled(true);
}
}
</script>
There are a few more solutions discussed here: http://forums.asp.net/t/1066976.aspx/9/10
I had this issue and I spent hours trying to fix it.
The solution ticked as answered will not fix the error only handle it.
The best approach is to check the IIS log files and the error should be there. It appears that the update panel encapsulates the real error and outputs it as a 'javascript error'.
For instance my error was that I forgot to make a class [Serializable]. Although this worked fine locally it did not work when deployed on the server.
I got this error when I had my button in the GridView in an UpdatePanel... deubbing my code I found that the above error is caused because of another internal error "A potentially dangerous Request.Form value was detected from the client"
Finally I figured out that one of my TextBoxes on the page has XML/HTML content and this in-turn causing above error
when I removed the xml/HTML and tested the button click ... it worked as expected.
I have got the same issue, here I give my problem and my solution hoping this would help someone:
Following other people recommendation I went to the log of the server (Windows Server 2012 in my case) in :
Control Panel -> Administrative Tools -> Event Viewer
Then in the left side:
Windows Logs -> Application:
In the warnings I found the message from my site and in my case it was due to a null reference:
*Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.*
And checking at the function described in the log I found a non initialized object and that was it.
So it could be a null reference exception in the code.
Hope someone find this useful, greetings.
Brother this piece of code is not a solution just change it to
<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args){
if (args.get_error() != undefined){
**alert(args.get_error().message.substr(args.get_error().name.length + 2));**
args.set_errorHandled(true);
}
}
</script>
and you will see the error is there but you are just not throwing it on UI.
This solution is helpful too:
Add validateRequest="false" in the <%# Page directive.
This is because ASP.net examines input from the browser for dangerous values. More info in this link
I also faced the same issue , and none of these worked. In my case this was fixed by adding these lines in config file.
<appSettings>
<add key="aspnet:MaxHttpCollectionKeys" value="100000" />
</appSettings>
<system.web.extensions>
<scripting>
<scriptResourceHandler enableCompression="false" enableCaching="true"/>
</scripting>
</system.web.extensions>
This is not the real problem, if you want to see why this is happening then please go to error log file of IIS.
in case of visual studio kindly navigate to:
C:\Users\User\Documents\IISExpress\TraceLogFiles\[your project name]\.
arrange file here in datewise descending and then open very first file.
it will look like:
now scroll down to bottom to see the GENERAL_RESPONSE_ENTITY_BUFFER
it is the actual problem. now solve it the above problem will solve automatically.
For those using the internal IIS of Visual Studio, try the following:
Generate the error message.
Break the debugger at the error display.
Check the callstack. You should see 'raise'.
Double click 'raise'.
Check the internals of 'sender' parameter. You will see a '_xmlHttpRequest' property.
Open the '_xmlHttpRequest' property, and you'll see a 'response' property.
The 'response' property will have the actual message.
I hope this helps someone out there!
Check your Application Event Log - my issue was Telerik RadCompression HTTP Module which I disabled in the Web.config.
#JS5 , I also faced the same issue as you: ImageButton causing exceptions inside UpdatePanel only on production server and IE. After some research I found this:
There is an issue with ImageButtons and UpdatePanels. The update to
.NET 4.5 is fixed there. It has something to do with Microsoft
changed the x,y axis of a button click from Int to Double so you can
tell where on the button you clicked and it's throwing a conversion
error.
Source
I'm using NetFramework 2.0 and IIS 6, so, the suggested solution was to downgrade IE compatibility adding a meta tag:
<meta http-equiv="X-UA-Compatible" content="IE=9" />
I've done this via Page_Load method only on the page I needed to:
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim tag As HtmlMeta = New HtmlMeta()
tag.HttpEquiv = "X-UA-Compatible"
tag.Content = "IE=9"
Header.Controls.Add(tag)
End Sub
Hope this helps someone.
I had the same issue, when i was trying out a way to solve it, i found out that the update panel was causing this issue. Depending on my requirement i could remove the update panel and get rid of the issue.
So it's a possible solution for the issue.
We also faced the same issue, and the problem could only be reproduced in the server (i.e., not locally, which made it even harder to fix, because we could not debug the application), and when using IE. We had a page with an update panel, and within this update panel a modalpopupextender, which also contained an update panel. After trying several solutions that did not work, we fix it by replacing every imagebutton within the modalpopupextender with a linkbutton, and within it the image needed.
Use the following code below inside updatepanel.
<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args){
if (args.get_error() != undefined){
args.set_errorHandled(true);
}
}
</script>
For me the problem was that I was using a <button> instead of a <asp:LinkButton>
Some times due to some code you get HTML tags in a text filed, like I was replacing some characters with new line BR tag of HTML and by mistake I also replaced it in the text that was supposed to be displayed in a Multiline text box so my multiline text box had a new line HTML tag BR in it coming dynamically due to my string replace function and I started getting this JavaScript error and as this HTML code was displayed in a text box that was in an update panel I start getting this error so I made the correction and all was fine. So before copying pasting anything please look at your code and see that all tag are closed proper and no irrelevant code data is coming to text boxes or Drop down lists. This error always come due to ill formed tags and irrelevant data.
My fix for this was to remove any HTML markup that was in the Text="" property of a TextBox in my asp.net code, inside an update panel. If you have more than one update panel on a page, it will affect them all, which makes it harder to work out which panel has the issue. Chris's answer above lead me to find this, but his is a very hidden answer but I think a very relevant one so here is an answer explained.
<asp:TextBox ID="bookingTBox" runat="server" ToolTip="" Width="150px" Text="<Auto Assigned>" CssClass="textboxItalicFormat"></asp:TextBox>
The above code will give this error.
The below will not.
<asp:TextBox ID="bookingTBox" runat="server" ToolTip="" Width="150px" Text="Auto Assigned" CssClass="textboxItalicFormat"></asp:TextBox>
In the second textbox code I have removed the < and > from the Text="" property. Please try this before spending time adding lines of script code, etc.
Had this problem when using AsyncFileUploader in an iFrame. Error came when using firefox. Worked in chrome just fine. It seemed like either the parent page or iframe page was loading out of sync and the parent page could not find the controls on the iframe page. Added a simple javascript alert to say that the file was uploaded. This gave the controls enough time to load and since the controls were available, everything loaded without an error.
I had this issue when I upgraded my project to 4.5 framework and the GridView had Empty Data Template. Something changed and the following statement which previously was returning the Empty Data Template was now returning the Header Row.
GridViewRow dr = (GridViewRow)this.grdViewRoleMembership.Controls[0].Controls[0];
I changed it to below and the error went away and the GridView started working as expected.
GridViewRow dr = (GridViewRow)this.grdViewRoleMembership.Controls[0].Controls[1];
I hope this helps someone.
This issue for me was caused by a database mapping error.
I attempted to use a select() call on a datasource with errors in the code behind. My controls were within an update panel and the actual cause was hidden.
Usually, if you can temporarily remove the update panel, asp.net will return a more useful error message.
" 1- Go to the web.config of your application "
" 2- Add a new entry under < system.web > "
3- Also Find the pages tag and set validateRequest=False
Only this works for me. !!
Be sure to put tilde and forward slash(~/) when CDN is the root directory. I think it's an issue in IIS
as my friend #RaviKumar mentioned above one reason of following problem is that some piece of data transferred from code to UI contain raw html tags which make request invalid for example I had a textarea and in my code I had set its value by code below
txtAgreement.Text = Data.Agreement
And when I compiled the page I could see raw html tag inside textarea so I changed textarea to div on which innerhtml works and render html (instead of injecting raw html tags into element) and it worked for me
happy coding
<add key="aspnet:MaxHttpCollectionKeys" value="100000"/ >
Add above key to Web.config or App.config to remove this error.
I got this error when I had ModalPopupExtender in the update panel... deubbing my code I found that the above error is caused because of updatepanel updatemode is conditional... so i change it to always then problem is solved.
This was working fine in my code.. i solved my issue.. really
Add below code in web.config file.
<system.web>
<httpRuntime executionTimeout="999" maxRequestLength="2097151"/>
</system.web>
answer for me was to fix a gridview control which contained a template field that had a dropdownlist which was loaded with a monstrous amount of selectable items- i replaced the DDL with a label field whose data is generated from a function. (i was originally going to allow gridview editing, but have switched to allowing edits on a separate panel displaying the DDL for that field for just that record). hope this might help someone.
This error: Uncaught Sys.WebForms.PageRequestManagerServerErrorException ....
i got in backend logic of one UpdatePanel when Oracle made exception because of mispelled column/table in sql command....

asp.Net <control> does not exist in current context

I am facing a problem: I have taken a dropdownList control and ID is
drpDownCountries in an ASP.NET project. The dropdownlist control is placed on page, in the code behind file of C#, while typing the control name drpDownCountries, this control ID is listed in object member list.
The code-behind code looks like this:
drpDownCountries.Attributes.Add("onBlur", "ErrorHighlight('" + drpDownCountries.ClientID + "','" + lblCountry.ClientID + "');");
But when I compile the project I am getting the following error:
Error: The name 'drpDownCountries' does not exist in the current context
I have checked this thing on different machines too, and the same error is occurring. I do not understand what the reason is or how to fix it.
Right-click on the ASPX (or ascx) file, and select Convert to web application (or something like that). That will force a refresh on the designer file.
I had this same problem and what worked for me was to make a change to the .ascx file in Design view and then save it. This finally forced Visual Studio to regenerate the designer.cs file and include my new control.
I have seen this error occur when there is a copy of the .aspx page in the project folder.
Example:
Error occurs in Test.aspx.
There is a Test-copy.aspx file in the project folder.
Delete, rename with a different extension, or move Test-copy.aspx to a different folder.
Error is resolved.
It's possible there is an error in your aspx/aspx file that is causing the designer file not to be updated correctly. You could confirm this by adding something new (eg. "") and see if you can access that. If not, something is probably broken in the markup that you'll need to fix.
So first check that your ascx document is defined like so
ExampleClass.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeFile="ExampleClass.ascx.cs" Inherits="ExampleClass" %>
ExampleClass.ascx.cs
public partial class ExampleClass : System.Web.UI.UserControl
{
protected void Page_Load(object sender, System.EventArgs e)
{
}
}
In aspx this type of error often occurs when you miss runat="server"
Do not let Intellisense fool you. Sometimes (usually after fixing problems with duplicate class names), you simply need to rebuild the project and the reported errors go away. Reopening the file after the build might be necessary.
You should put some code to get help..
Anyway, the problem could be that drpDownCountries is contained within a Panel control.
The Panel control is a Container control, in that it can hold lots of
controls.
In order to access the controls within that Panel control,
you first need to "help" ASP.Net to find it.
The typical way of doing this is to use the FindControl method look here.
Code sample:
DropDownList myDrop = (DropDownList)this.Panel1.FindControl("drpDownCountries");
if(myDrop != null)
{
..somecode..
}
Recreate the project. Just create a new project and add the elements one by one and hope it won't happen again. If it does, well that's part of the Microsoft experience: recreate another project and so on, until you decide to quit your job and join open-source.
CORRECTION
I'm going to redo the project that I have been working on since the last 3 days using ASP .NET MVC. I should be using an open-source tech for sure, but too bad it's not my decision for this project to not use .NET.
If this is happening after copy/move pages to new location, or project, you may simply check if PageName.ascx.designer.cs is included in project.
There is a bug in visual studio (or maybe reshrper): It includes PageName.ascx and PageName.ascx.cs, but not PageName.ascx.designer.cs, which must be included manually.
The only thing that worked for me was to add a temp controller in the aspx file and saving it.
That generated the designer again, and my controllers are now recognized!
You can then remove the temp controller and save; it won't ruin anything.

RadControl DateTimePicker Selecting new time doesn't remove highlight from previous selection

This is not browser specific - the behavior exists in Firefox and IE. The RadControl is being used within a User Control in a SiteFinity site.
Very little customization has been done to the control.
<telerik:RadDateTimePicker ID="RadDateTimePicker1" runat="server"
MinDate="2010/1/1" Width="250px">
<ClientEvents></ClientEvents>
<TimeView starttime="08:00:00" endtime="20:00:00"
interval="02:00:00"></TimeView>
<DateInput runat="server" ID="DateInput"></DateInput>
</telerik:RadDateTimePicker>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RadDateTimePicker1.MinDate = DateTime.Now;
}
}
[Disclaimer, I work for Telerik]
I don't specifically know what the issue is, however here are some general troubleshooting steps that might help unearth the issue:
Check for Javacript errors - (Firefox's Error Console would do it)
Isolate the RadDateTimePicker control from Sitefinity - (Create a normal ASPX page and place the RadDateTimePicker control on this page. Does it work in this environment?)
Check for stylesheet issues using Firebug and/or remove stylesheets (backup first).
In general, keep simplifying until it starts working then re-add complexity until it breaks again. This normally tells me where the problem is.
Alternately, you could send your project/code to Telerik support. Best of luck.
Can you try changing MinDate to use:
RadDateTimePicker1.MinDate = System.DateTime.Parse(String.Format("{0}/{1}/{2}", System.DateTime.Now.Month, System.DateTime.Now.Day, System.DateTime.Now.Year - 1))
And tell me if the behavior changes.
Also, is the new highlight being shown as well, or is it stuck on the old highlighting completely?

ASP.Net: Page_Load() being called multiple times

I don't know alot about ASP.Net but I'm trying to make a new control for a message box. You enter some info and press a button.
However, for some bizarre reason when the button is pressed, Page_Load() gets called a second time, and all of the member variables are reset to null! I need those variables, and Page_Load() has not reason to be called a second time! Of course the callstack is useless.
Remember, in ASP.Net every time you cause a postback of any kind, including handling events like button clicks, you're working with a brand new instance of your page class that must be rebuilt from scratch. Any work you've done previously to build the page on the server is gone. That means running the entire page life cycle, including your page load code, and not just the click code.
Always two there are, no more, no less. A request and a response.
When the page posts back, the Page_Load method is called. Then, once the server actually processes the page and sends you a new one based on changes, the Page_Load is called again, actually the first time on the new page sent to you.
So if you are pulling data in the Page_Load event or setting some values, enclose it in the following block:
if(!Page.IsPostBack)
{
}
to preserve some of your state. Otherwise, the instructions that you put into the Page_Load event will execute every time.
It helps to review the ASP.Net page lifecycle :)
As Joel mentioned, instance variables will be lost once the page is sent back to the client. However, there are various methods of storing the values of your variables so you can retrieve them later. This page on State Management is a good starting point if you want to learn more.
Any tag/element which requires url reference like img, anchor, object etc must be checked for the empty reference.
e.g. href="", url="", src="" are some common errors.
This code works for me:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["something"] == null)
{
Session["something"] = "1";
}
else
{
Session["something"] = null;
//your page load code here
}
}
}
For me, the issue was a bit complicated, but I found that the
protected override void OnPreRender(EventArgs e)
handler is only called once, so it's safer to put some actions in there if it's not too late in the pipeline for you.
An extension of #user3207728's response, I found this link explains it well and has a simple solution...
http://www.aspdotnet-suresh.com/2010/04/detect-browser-refresh-to-avoid-events.html
Unfortunately checking just for if (!Page.IsPostBack) is not enough as IsPostBack will always be FALSE on a refresh.
Just a shot in the dark but maybe add this after your page_load:
if (!IsPostBack)
{
you can use sessions or viewstate to retain the values of variables..
if you want to redirect to a different page , use session[]
else if you want to stay on the same page , use viewstate[]
In my Case the Problem Was Related to Iframe, One Time I removed the Iframe Everithing Work Fine
<iframe id="pdf2"
src="#"
width="100%"
height="100%">
</iframe>

Categories

Resources