I'm having a bit of a pain here and I just can't figure out what's wrong.
I have an ASP.net project which I deployed on a server. At first everything seemed allright, no Errors whatsoever. However, as a last adition I wanted to add a search function to a fairly large list so I added the following syntax to my mark-up:
<td>
Search Server:
<asp:TextBox ID="txtSearch" runat="server" />
<asp:Button ID="btnLookup" runat="server" OnClick="btnLookup_Clicked" Text="Search" />
<asp:Label ID="lblFeedback" runat="server" />
</td>
and the following in code behind:
protected void btnLookup_Clicked(object sender, EventArgs e)
{
lblFeedback.Text = "";
Session["IsSearch"] = true;
LoadServerList();
}
When I run this locally it works just fine as I expect.
HOWEVER!
When I copy these files to the server I get a compilation error:
Compiler Error Message: CS1061: ' ASP.ntservice_ reports_ reports_ serverlist_ manage_ aspx ' does not contain a definition for 'btnLookup_ Clicked' and no extension method 'btnLookup_ Clicked' accepting a first argument of type 'ASP.ntservice_ reports_ reports_ serverlist_ manage_ aspx' could be found (are you missing a using directive or an assembly reference?)
it says there is nothing that handles my Clicked event although it does work when I run it through Visual studio.
any ideas?
EDIT:
What I tried myself is
renaming button
deleting and readding the button
add through designer
renaming click event
removing the event from markup allows normal execution ... :/
Is your project a web site or a web application? I would guess that it's a web application project and that perhaps you don't have the latest DLL deployed from the bin folder. Check the versions between your machine and the server to verify that they are the same.
I think this error is generated when you change an object Name, ex.
Text1 -» txtSerialNo I had the same problem but I could fix it. Here is the solution:
Go to Split Mode, click on the textbox/object, in the code remove the line
[**ontextchanged="txtSerialNo_TextChanged"**]
From:
[<asp:TextBox ID="txtSerialNo" runat="server"
ontextchanged="txtSerialNo_TextChanged"></asp:TextBox> //remove this line]
To:
[<asp:TextBox ID="txtSerialNo" runat="server"</asp:TextBox>]
I hope it works for you. Bless you.
I experienced same problem. And I made the event handler method public, problem solved!
Thanks!
Did you deploy the dll?
Do you set
<%# Page ... Language="C#" CodeBehind="... .aspx.cs" Inherits="..." .../>
in your page directive correctly?
This should fix it if you did everything else right:
Try to make an entirely new click event (using the split view, just to be sure you get the method signature right.)
Then copy your code from your previous clicked event into the newly created event, copy the new event's method name to your original button and see if it works.
Try renaming the event handler to some thing OnClick="buttonLookup_Clicked"... and changing the event handler signature to match it.
having the same issue myself, I made the method public so that removed the compiler error, then followed that with including everything within
<form runat="server">
.....
<asp:Button id... OnClick="MethodName"/>
</form>
Hope this helps
Make the events your onclick events point to public.
This can happen if the event is signed-up for programmatically AND also in the markup (via the properties)
go to Build ==> Clean Solution ==> Run (f5)
I just restarted my ASP.NET Development server then its running again.
I experienced the same problem with you, but I fix it by include CodeFile="xxxx.aspx.cs" into my page directive, hope this help.
Right Click on the form which affected and go to properties, change the Build Action to Compile. typically this error comes when the Build Action changed to resource.
In my case this issue occurs when there are two projects in solution, and the second project has reference of first project dll.
When you add new members to the class in first project make sure you build the first project first and then second project will compile successfully
Related
I am getting the below detailed error:
Invalid postback or callback argument. Event validation is enabled using in configuration or <%# Page EnableEventvalidation =”true” %> in a page. For security purpose, this feature verifies that arguments to postback or callback events originate from the server that originally rendered them.
I am having a webpart page with a webpart where i do have a UPdatePanel and a button Upon Button click i am getting this error.
the same package(wsp) which we are using in one of our environment is working fine and the same is not working in another environment.
Help in this is highly appreciable.
Without code it will be incredibly difficult to diagnose your issue.
You mentioned that your utilizing an Update Panel, which in essence will automatically store your page in memory, then it will render the proper Ajax to hide the Postback. The Microsoft Developer Network (MSDN) basically warns you when you use the EnableEventValidation with Client-Side modification.
If you write client script that changes a control in the client at run
time, you might have to use the RegisterForEventValidation method in
order to avoid false event validation errors.
Also if you initialize out of your web.config and directly in code, you should ensure that you call the validation before the page has been initialized. So I would potentially use:
protected void Page_PreInit()
{
// Before Page Initialization
}
Which would potentially eliminate any errors from the front-end, without code can't be of more assistance.
Ok without some code to go on I'll fire some rounds off into the dark, I know next to nothing about SharePoint so I maybe missing something obvious here:
Firstly, check your environments, one may have a different web.config which has EnableEventValidation set to false.
Secondly on Page_Load are you doing any DataBind? Depending on whatever your code is doing you may need make sure it's not binding on PostBack - or if it is already; try binding on PostBack.
Thirdly; any html or < > characters being included anywhere in the form? Also line breaks in data (my memory is a bit hazy on this one) I seem to remember, something like:
<option value="
my value
">select this</option>
Could cause it too. So doing a Trim() on data is recommended.
Lastly: Tag bleed out, check none of your tags are unclosed, something like <span <asp:TextBox [...] /> this could be the cause too.
add EnableEventValidation="false" in page directive <%# Page EnableEventValidation="false" %>
I seem to be having a problem with my button's OnClick, it doesn't even react at all to the event. It responds to OnClientClick and executes the code, but when I try to relate it o a function in my .aspx.cs class it just ignores it, and it should be executing very simple code (writing to the output debug)
I've checked every other stackoverflow post about this I could find and no one had the same issue.
I know that my Index.aspx is executing the code inside Index.aspx.cs because the Page_Load function is outputting to the debug window, so that's not the problem.
Here's the important code:
<asp:Button ID="btnCreateOrder" runat="server" Text="Create Order" OnClick="btnClick" />
protected void btnClick(object sender, EventArgs e)
{
System.Diagnostics.Debug.Write("Testing3");
}
Like I said the Page_Load function is working fine so it's not an issue of them not being connected.
DIFFERENT PROBLEM IF YOU FEEL SO INCLINED:
While you're reading, I also have a problem of not being able to find objects from my HTML in my CS file.
What I mean by that is, if I reference this label:
<asp:Label ID="testLabel" runat="server" Text="test"></asp:Label>
by saying
testLabel = "Test2";
I get the error "The name 'testLabel does not exist in the current context"
And if I try to reference it by saying this:
Index.testLabel = "Test2";
I get "'MyProject.Views.Home.Index' does not contain a definition for 'testLabel'" even though it clearly does.
Maybe the .designer file is bad.
Try this: delete the .designer.cs file of your .aspx page, right-click on it and select the 'Convert to web application' option.
EDIT: As for the Button event, how did you generate the method stub for the click event? Did you click the button on the designer view twice and the visual studio generated id for you or did you handcoded it?
Try to delete both the button and the button click event, and when you declare the button again, double click it on the designer view.
There are many questions with same name as this one, but I haven't found solution.
MasterPage.master:
<div id="dateShow">
<asp:Label ID="lblDateShow" runat="server"></asp:Label>
</div>
MasterPage.master.cs:
protected void Page_Load(object sender, EventArgs e)
{
lblDateShow.Text = DateTime.Now.ToShortDateString();
}
It happens on building and show me the error, but if I run without building (before run-->no build) it shows me the date. It happens only in master page with all controls that I want to add, on other pages all work fine. What could be the problem?
Error Message is:
Error 1 The name 'lblDateShow' does not exist in the current context
Long discription:
Warning 2 The type 'MasterPage' in 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\thegame\6da1e5d1\9152b07\App_Web_tmu2ya5i.4.cs' conflicts with the imported type 'MasterPage' in 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\thegame\6da1e5d1\9152b07\App_Web_masterpage.master.cdcab7d2.k9aa16y-.dll'. Using the type defined in 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\thegame\6da1e5d1\9152b07\App_Web_tmu2ya5i.4.cs'. c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\thegame\6da1e5d1\9152b07\App_Web_tmu2ya5i.4.cs
I tried to delete Temp files, didn't help..
UPD I solved that problem. I Had another masterpage2.master and somehow he did all the problems. When I created label or other control, he was declared in second master page, I don't know how can it be))
It happend with me and I took some days until discovery that I had one more page with the same code behind (CodeFile="PageName.aspx.cs") wich did not have the control ID. I just deleted it and the problem was deleted together.
If lblDateShow is in the markup of your master page, but it appears not to exist in the code-behind file, then it is most likely a problem with the designer.cs file for your master page. Is lblDateShow instantiated there? If not, you will need to regenerate your designer file or add the Label manually.
Try putting it in the right namespace. That was my issue
I have default.aspx with a "Submit" Button and a code behind function called as "btn_Submit" which will perform submit action. Once I deploy the application and if there is any logical problem in btn_Submit code, then I can use runat=server script in default.aspx file and I need not go for another deployment.
But When I tried the same for ascx file, it works very well in development environment i.e in VS but when I move the same to Test server, system throws function not defined. I have renamed the existing function name.
So is it possible to add runat=server script and add c# code in ascx file?
Yes it is possible..
You have to surround your code with markup
<script language="c#" runat="server">
public void Page_Load(object sender, EventArgs e)
{
//hello, world!
}
</script>
Take a look to thisquestion! I think it will help you..
But it is really better to separate your code..
Did you tell the button which method to run on submit? With "auto event wireup" it will try to find a "buttonname_Click" method if you didn't specify anything. If that doesn't exist, you will get an error.
To call a method with a different name, specify that in the OnClick property of the button.
I am not sure why this happened and still was not able to solve it, So redeployed the application :(
I have the following button on a .aspx page:
<asp:Button runat="server" ID="bntLogin" OnClick="bntLogin_Click" Text="Login" />
With the following in the .aspx.cs:
protected void bntLogin_Click(object sender, EventArgs e)
{
//
}
When I try to build it I get the following error:
'ASP.reserve_aspx' does not contain a definition for 'bntLogin_Click' and no extension method 'bntLogin_Click' accepting a first argument of type 'ASP.reserve_aspx' could be found (are you missing a using directive or an assembly reference?)
However, when I move the click event from the code-behind to a script block inside the markup it builds.
Any ideas?
Are you sure that you placed the method in the correct code-behind file?
Check which file you are using as your code-behind file by looking at the #page directive at the top of the aspx file itself (check the inherits attribute) - you may be surprised.
A loosely-related side note: By setting the OnClick with a string value that corresponds to the method you wish to invoke you are implicitly relying on ASP.NET's AutoEventWireup feature which I don't consider to be a good approach. It is better to manually wire up your controls in your page's OnInit override method like this:
bntLogin.Click += bntLogin_Click;
By relying on AutoEventWireup you are allowing the ASP.NET runtime to create this code for you and since this happens at execution time you are incurring an execution time performance penalty as well as risking an exception like the one you are seeing now.
I usually hook up the events in the code-behind's OnInit method, which is a hold-over from ASP.NET 1.1 (that's where the designer would put it back then.)
If by any chance you're still running ASP.NET 1.1, delete the aspnet_client folder, rebuild and try again.