0

我正在提交以下表格:

 <td colspan="2">
  <asp:TextBox Width="100%" Height="200px" ID="NoteTextBox" CssClass="tb_sm"  Style="text  align:left"
     runat="server" TextMode="MultiLine"></asp:TextBox></td></tr>
 <tr><td align="right"> <asp:Button ID="Done" runat="server" Text="Done" OnClick="Done_click"/></td>

 public string Done_click(object sender, EventArgs e) {
        String a = NoteTextBox.Text;
        // on the basis of that value i have to return a string
          if(a == "xyz") {retrun "Ok"}
          else {return "nop"}
      }

根据某些条件从Done_click方法返回一个字符串,我没有得到的是在给定的打印返回值ID=NoteTextBox

我该怎么做?

4

3 回答 3

1

试试看。

public string Done_click(object sender, EventArgs e)
{
    String a = NoteTextBox.Text;
    // on the basis of that value i have to return a string
      if    (a == "xyz") 
      {
            form1.Controls.Add( new Literal( { ID = "Literal1", Text = a } ) );
                or 
           Response.Write(a); // It will write at the top of the page so use above code
      }
      else 
       {
            form1.Controls.Add( new Literal( { ID = "Literal1", Text = "nop" } ) );
       }
  }
于 2012-08-23T18:37:35.927 回答
0

因为为了在 asp.net 中打印值,就像 php 一样,您使用echo. 在 asp.net 中,您必须使用Response.Write()Method;

String a = NoteTextBox.Text;
if(String.Compare(a, "xys") == 0)
{
       Response.Write("ok");
}
else
{
    Response.Write("Not ok");
}

您将在页面顶部看到输出。我还提到了 String.Compare() 如果成功则返回 0。它基本上是.net String 类方法。

于 2012-08-23T18:38:14.923 回答
0

您可以使用 Response.Write() 来测试您的回报;

public string Done_click(object sender, EventArgs e) {
        String a = NoteTextBox.Text;
        // on the basis of that value i have to return a string
          if(a == "xyz") {Response.Write(a);}
          else {Response.Write("nop");}
      }

您在屏幕顶部的响应流上打印

您还可以在屏幕上添加标签,并设置值

LabelTest.Text = a;
于 2012-08-23T18:32:23.377 回答