hello
im a beginner in web programming
and i faced a problem

i defined a button in a certain page say contact.aspx
when i choose button_click event it appears in
which is not correct coz i lost my control to the page contact.aspx

waiting for ur answers .. thanks

Dani AI

Generated

Good catch by and well spotted by — the designer will create an event handler in whatever code-behind the page markup is wired to. That mapping (the page directive and the class name the page inherits) controls where Visual Studio puts generated methods, so if the markup points at the wrong code file or class, double-clicking a control will open/create the handler in that wrong file.

Why it happens (brief):
Visual Studio uses the page's markup-to-class mapping to decide where to insert generated code. Copying/renaming pages, moving files between projects, or mixing Web Site vs Web Application project styles often leaves that mapping inconsistent. The result: new event handlers end up in the file/class referenced by the page, not necessarily the file you expect.

Quick checklist to fix and avoid it again

  • Verify the page markup’s mapping attributes and the code-behind class name/namespace match each other.
  • Open the code-behind and confirm the class name (and namespace) equals what the page inherits; for Web Application projects ensure the designer file exists and the class is partial.
  • If the handler was created in the wrong file, cut it from there and paste it into the correct code-behind. Make sure the method signature matches the event (example signature shown below).
  • Rebuild or use “Convert to Web Application” to regenerate the designer file when it’s out of sync.
  • When renaming or moving pages, do it from within Visual Studio rather than just the file system so the mappings update correctly.
  • Consider consistent use of one project model (Web Site vs Web Application) to avoid confusion.

Example handler signature (C#)

protected void Button_Click(object sender, EventArgs e)
{
    // handler code
}

Caution: keep only one active handler for the same control to avoid duplicate calls. The steps above will prevent the designer from putting new handlers into a different page in future.

Recommended Answers

All 2 Replies

Pls. check your HTML Source page in contact.aspx and defaulf.aspx
Codebehind="" ???

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="frmAnnouncmentsAndMemos.aspx.vb" Inherits="HR_Common.frmAnnouncmentsAndMemos"%>

Mark as solved, if it helps you!!!

as i expected .. too simple but i wasn't able to discover this

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

now i know it .. :)
thanks 4 ur help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.