Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when i make asp:button in .ascx page ,
it is not clickable (i mean when clicked, the function in .ascx.cs is not called..)

for exp.. my page is tester.ascx
i call as
<asp:button id="ButtonDef" text="Search" OnClick="ButtonDef_Click" runat="Server">


and in tester.ascx.cs , i have

protected void ButtonDef_Click(object sender, EventArgs e)
    {
}

but that is not called

and in source , i get as

<input id="ctl00_ContentHome_UserSearchBoxControl_ButtonDef" type="submit" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentHome$UserSearchBoxControl$ButtonDef", "", true, "", "", false, false))" value="Search" name="ctl00$ContentHome$UserSearchBoxControl$ButtonDef"></input>
Posted
Updated 12-Jan-14 20:05pm
v6
Comments
maulikshah1990 13-Jan-14 1:47am    
no..i call function in ascx.cs file
JoCodes 13-Jan-14 1:50am    
Which is the code you are using? Posted in the comment or as part of the question?
maulikshah1990 13-Jan-14 1:50am    
posted in comment
JoCodes 13-Jan-14 1:52am    
Then remove the code in teh question and update it with the relevant one.
maulikshah1990 13-Jan-14 1:54am    
i removed from main question ,,, now is it ok ???

May be this is your solution.

http://forums.asp.net/t/1078069.aspx[^]
 
Share this answer
 
Comments
maulikshah1990 13-Jan-14 2:24am    
thanks everbody..
i got the error..

actually i used <asp:RequiredFieldValidator ID="SBRequiredFieldValidator2" ControlToValidate="SBcheckindate" Text="The Checkin field is required!"
runat="server" />
which caused button click event to call
Gandalf_TheWhite 13-Jan-14 2:32am    
So I guess your problem is solved, right?
maulikshah1990 13-Jan-14 2:48am    
yes.. i debugged the error and solved it
Gandalf_TheWhite 13-Jan-14 2:52am    
Glad! :)
User Control source file :

XML
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<asp:Button id="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click"/>



And CS file:

C#
protected void Page_Load(object sender, EventArgs e)
   {

   }
   protected void btnSubmit_Click(object sender, EventArgs e)
   {
       Response.Write("Hello UserControl");
   }


And Page Source file:

XML
<%@ Register Src="~/WebUserControl.ascx" TagName="user" TagPrefix="btn" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <btn:user id="btn1" runat="server"/>
</asp:Content>


working fine
 
Share this answer
 
Refer:http://asp.net-tutorials.com/user-controls/events/[^]
or hit this link
User controls in ASP .NET[^] in this link you can also download a complete solution.
This may help.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900