在多视图中无法获取文本框值

本文关键字:获取 取文本 视图 | 更新日期: 2023-09-27 18:30:23

我创建了一个多视图,里面有两个视图,一个用于一些信息,另一个用于发送消息。对于第一个视图来说一切正常,但对于第二个视图,当我单击它时,消息的提交按钮不会响应,也不会触发其功能。
有什么建议如何使其工作吗?

.HTML:

<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
        <ContentTemplate>
            <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
            <asp:View ID="View1" runat="server">
            <asp:Button ID="SendPM" style="margin-left: 112px; width: 170px; height: 30px; font-size: 20px; border-radius: 15px;" runat="server" Text="Send PM" onclick="SendPM_Click"/>
                <div style="position:relative; top: 3px; margin-left: 20px; font-size: 25px; color: black;">
                <i><% Response.Write(Session["ProfileEmail"].ToString()); %></i>
                </div>
                <br />
                <div style="margin-left: 35px; font-size: 20px; color: black;">
                <span style="font-size: 23px;">Firstname:</span> <i style="color:Green;"><% Response.Write(Session["ProfileFirstName"].ToString()); %></i>
                <br />
                <span style="font-size: 23px;">Lastname:</span> <i style="color:Green;"><% Response.Write(Session["ProfileLastName"].ToString()); %></i>
                <br />
                <span style="font-size: 23px;">PhoneNumber:</span> <i style="color:Green;"><% Response.Write(Session["ProfilePhoneNumber"].ToString()); %></i>
                <br />
                <span style="font-size: 23px;">Age:</span> <i style="color:Green;"><% Response.Write(Session["ProfileAge"].ToString()); %></i>
                </div>
            </asp:View>
            <asp:View ID="View2" runat="server"> <!-- Here is the view for the message -->
            <asp:Button ID="GoToDetails" style="margin-left: 112px; width: 170px; height: 30px; font-size: 20px; border-radius: 15px;" runat="server" Text="Details" onclick="GoToDetails_Click"/>
            <br />
            <br />
                <div style="margin-left: 50px;">
                    Title: <asp:TextBox ID="TitleOfPM" runat="server" ValidationGroup="messagegroup"></asp:TextBox>
                    <br />
                    <br />
                    Content: 
                    <asp:TextBox ID="ContentOfPM" TextMode="MultiLine" runat="server" ValidationGroup="messagegroup"></asp:TextBox>
                    <br />
                    **<asp:Button ID="SubmitPM" runat="server" Text="Submit" onclick="SubmitPM_Click" ValidationGroup="messagegroup" />**
                </div>
            </asp:View>

        </asp:MultiView> 
                 </ContentTemplate>
                     </asp:UpdatePanel>



代码隐藏:

protected void SendPM_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 1;
    }
    protected void GoToDetails_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 0;
    }
    protected void SubmitPM_Click(object sender, EventArgs e)
    {
        PrivateMessageInfo message = new PrivateMessageInfo();
        PrivateMessages u = new PrivateMessages();
        message.title = TitleOfPM.Text;
        message.content = ContentOfPM.Text;
        message.PMSender = Session["email"].ToString();
        message.SentTo = Session["ReplicateForEmail"].ToString();
        DateTime dt = DateTime.Now;
        message.SendDate = dt.ToShortDateString();
        u.SendPrivateMessage(message);
        Response.Redirect("HomePage.aspx?JobID=" + JobID);
    }

在多视图中无法获取文本框值

你能检查一下是否在设计器.cs文件中定义了按钮吗?