Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Michael Falch Madsen 70 posts 92 karma points
    Nov 12, 2010 @ 10:32
    Michael Falch Madsen
    0

    User Control

    Im having issues with my usercontrols submit buttons not submitting.

    I've made a small test which do not work :/

    test.ascx:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="test.ascx.cs" Inherits="test.test" %>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <asp:Button ID="btn_klikher" runat="server" onclick="btn_klikher_Click"
        Text="Click me" />

    test.ascx.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace test
    {
        public partial class test : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if(!Page.IsPostBack) {
                    Label1.Text = "Click the button";
                }
            }

            protected void btn_klikher_Click(object sender, EventArgs e)
            {
                Label1.Text = "Thank you";
            }
        }
    }

     

    It writes fine "Click the button" but nothing happens when i do???? It's the same for all my other usercontrols

  • frank-frank 22 posts 45 karma points
    Nov 13, 2010 @ 19:46
    frank-frank
    0

    Hi Michael,

    your asp:Button and asp:Label (and all other elements you will add to your form) must be wrapped with a form element:

    <form id="form1" runat="server">

    <asp:Label ID .... >

    <asp:Button ID="btnSubmit" runat="server" Text="Click me" OnClick="btnSubmit_Click"  />

    </form>

    The form element should actually be used in masterpage layout (and not the user control) in order to work for the entire page. Check your HTML Source code after it's rendered in the browser if you have the form element.

    Cheers,

    Frank

  • Michael Falch Madsen 70 posts 92 karma points
    Nov 13, 2010 @ 21:51
    Michael Falch Madsen
    0

    I have the <form runat="server"> in the master page.

    I've somehow got it working but not when i create a new project and adds a new usercontrol - but if i edits one and only one of my erlier test projects it works??? The thing im currently struggling with is RequiredFieldValidators that do not work! The form submits but the validator is not called, and if i have 2 usercontrols on the same page both gets submittet... Have no idea of what the heck is going on :/

Please Sign in or register to post replies

Write your reply to:

Draft