Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用户控件按钮未从webform页面触发_C#_Asp.net_.net_User Controls_Updatepanel - Fatal编程技术网

C# 用户控件按钮未从webform页面触发

C# 用户控件按钮未从webform页面触发,c#,asp.net,.net,user-controls,updatepanel,C#,Asp.net,.net,User Controls,Updatepanel,我已经为访问者创建了一个用户控件来订阅时事通讯 UserControl正在使用更新面板并添加到主母版页 控件的问题在于订阅按钮由于某种原因并没有启动 用户控件标记: <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <table cellpadding="0" cellspacing="0" class="PrayerTimeWrapper">

我已经为访问者创建了一个用户控件来订阅时事通讯

UserControl正在使用更新面板并添加到主母版页

控件的问题在于订阅按钮由于某种原因并没有启动

用户控件标记:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>    
    <table cellpadding="0" cellspacing="0" class="PrayerTimeWrapper">
        <tr>
            <td align="center">
                <table cellpadding="0" cellspacing="0" class="PrayerTimeInnerWrapper" border="0">
                    <tr>
                        <td valign="top">
                            <div class="dHeading"><asp:Label ID="lblTitle" runat="server" Text="JOIN US"></asp:Label></div>
                            <div class="dName">
                                <asp:TextBox ID="txtName" CssClass="txtSubscribe" runat="server" Text="NAME" onfocus="if(this.value=='NAME')this.value='';" onblur="if(this.value=='')this.value='NAME';"></asp:TextBox>
                            </div>
                            <div class="dEmail">
                                <asp:TextBox ID="txtEmail" CssClass="txtSubscribe" runat="server" Text="YOUR EMAIL" onfocus="if(this.value=='YOUR EMAIL')this.value='';" onblur="if(this.value=='')this.value='YOUR EMAIL';"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="rfvEmailSub"  runat="server" ErrorMessage="*" 
                                    ControlToValidate="txtEmail" ValidationGroup="SubEmail" ></asp:RequiredFieldValidator>
                                <asp:RegularExpressionValidator ID="revEmailSub" runat="server" 
                                    ErrorMessage="*" ControlToValidate="txtEmail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" 
                                    ValidationGroup="SubEmail" ></asp:RegularExpressionValidator>
                            </div>
                            <div class="dSubmit">
                                <asp:Button ID="btnSubscribe" CssClass="btnSubscribe" runat="server" Text="Subscribe" onclick="btnSubscribe_Click" />
                            </div>   
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>    
    </ContentTemplate>
</asp:UpdatePanel>
使用母版页的页面的标记:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="PrayerTiming.aspx.cs" Inherits="PrayerTiming" %>
<%@ Register Src="~/en/UserControls/ucSubscribe.ascx" TagName="Subscribe"  TagPrefix="uc"%>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />    
    <div align="center" id="table"></div>    
    <uc:Subscribe id="ucSB" runat="server" UpdateMode="Conditional" />    
</asp:Content>


我在某处做错了什么,但我不知道是什么。如果您能提供帮助,我将不胜感激。

同时为btnSubscribe按钮设置ValidationGroup

<asp:Button ID="btnSubscribe" 
      CssClass="btnSubscribe" runat="server" 
      Text="Subscribe" 
      onclick="btnSubscribe_Click" 
       ValidationGroup="SubEmail" />

更新

从我在评论和其他答案中看到的情况来看,按钮没有将内容发布到服务器的唯一原因是它没有订阅该验证组。ValidationGroup用于分离页面中的某些视图(控件组),以便它们使用自己的验证。例如,忘记密码部分和登录部分将有两个不同的验证组,因此当单击某个按钮时,仅验证其部分


我做了这个更新,因为我真的认为被接受的答案更像是一个调试建议,而不是一个实际的答案。未来的SO读者可能会跳转使用此指南,而不是看到问题。

尝试在
表单中使用
runat=“server”
标记
UpdatePanel

使用
响应。在
异步重新请求期间写入
可以更改用于更新的数据。请依赖更新面板中的控件


因此,不要使用
Response.Write(“Test”)
而使用
Label.Text=“Test”

按钮事件未触发。。。当我调试页面时,当您单击“订阅”按钮时,页面是否会发布到服务器?只是出于好奇,该网站的用途是什么?它是一个普通网站,只有很少的web表单和简单的新闻稿订阅。。我认为我一刻也没有得到它,即使在添加了验证组之后,仍然没有发生任何事情。按钮事件不可用firing@KnowledgeSeeker,Response.Write的问题是,当使用UpdatePanel时,它的工作方式与您所看到的正常方式(非AJAX方式)不同。通常情况下,您会在页面顶部看到编写的文本,而不是任何其他html代码,但使用AJAX时,它不会这样工作。我不知道用AJAX写的文本放在哪里,你可以用Fiddler看到它。@KnowledgeSeek:问题是,当有人在异步重新请求过程中使用
Resonse.Write
时,他更改了用于更新控件的数据,状态“与验证无关”我正在使用母版页,因此我无法将表单标记添加到用户控件中。我是通过将response.Write语句替换为正确的标签控制,效果良好。谢谢你的帮助。Thanks@KnowledgeSeeker,你说你调试了这个,显然你没有,因为跟踪例程解决了你的问题。我想知道在你删除ValidationGroup=“SubEmail”后它是否仍然有效。@Adrian lftode,当你指出validation group时,我认为这是唯一的问题。令我惊讶的是,在那之后,它就不起作用了。最后,我对代码做了一些更改,使它起作用&其中一个更改是删除response.write语句。当我尝试“Anouar204”中提到的类似方法时,我仍然不清楚为什么它不起作用。不管怎么说,我感谢大家的帮助。甚至在我的问题解决之前,我就已经给出了你的回复投票。@Adrian,如果我删除验证组ValidationGroup=“SubEmail”,它将不起作用
<asp:Button ID="btnSubscribe" 
      CssClass="btnSubscribe" runat="server" 
      Text="Subscribe" 
      onclick="btnSubscribe_Click" 
       ValidationGroup="SubEmail" />