Skip to main content
 首页 » 编程设计

c#之asp.net 控件无法获取值或文本

2024年02月23日15落叶无声

我的页面上有一个 cleEditor,它需要 rows=""cols=""而当我执行 runat="Server"时,asp.net 不喜欢这个

为了解决这个问题,我尝试使用 FindControl,但我似乎无法通过这种方式获取值。

这是我的代码:

protected void os_submit_Click ( object sender, EventArgs e ) 
{ 
    Control cleEditor = FindControl( "editor2" ); 
    MailMessage mm = new MailMessage( "OnlineSignup@help.com", "help@help.com" ); 
    mm.Subject = "Online Signup Checklist"; 
    mm.Body = cleEditor.value; // Trying to grab the value of the textarea 
    mm.IsBodyHtml = true; 
    SmtpClient smtp = new SmtpClient(); 
    smtp.Host = "127.0.0.1"; 
    smtp.Port = 25; 
    smtp.Send( mm ); 
} 

我有一个 ID 为 editor2 的 TextArea。在幕后,jquery 将它变成了富文本编辑器。我需要 asp.net 才能获取此文本区域的值/文本。

谁能看出我做错了什么?

请您参考如下方法:

不要将 runat="server" 放在 TextArea 上并执行此操作:

protected void os_submit_Click ( object sender, EventArgs e ) 
{ 
    MailMessage mm = new MailMessage( "OnlineSignup@help.com", "help@help.com" ); 
    mm.Subject = "Online Signup Checklist"; 
    mm.Body = Request.Form["editor2"]; // Trying to grab the value of the textarea 
    mm.IsBodyHtml = true; 
    SmtpClient smtp = new SmtpClient(); 
    smtp.Host = "127.0.0.1"; 
    smtp.Port = 25; 
    smtp.Send( mm ); 
}