ASP.NET - How to write some html in the page? With Response.Write?

前端 未结 8 1439
星月不相逢
星月不相逢 2020-12-31 00:52

I need that some html in the area in the asp.net page that i am coding, is changed according to a string variable. I was thinking about creating a label, and then change the

相关标签:
8条回答
  • 2020-12-31 01:07

    why don't you give LiteralControl a try?

     myLitCtrl.Text="<h2><p>Notify:</p> Alert</h2>";
    
    0 讨论(0)
  • 2020-12-31 01:08

    ASPX file:

    <h2><p>Notify:</p> <asp:Literal runat="server" ID="ltNotify" /></h2>
    

    ASPX.CS file:

    ltNotify.Text = "Alert!";
    
    0 讨论(0)
  • 2020-12-31 01:14

    You can also use pageMethods in asp.net. So that you can call javascript functions from asp.net functions. E.g.

     [WebMethod]
        public static string showTxtbox(string name)
        {
             return showResult(name);
        }
          
        public static string showResult(string name)
        {
            Database databaseObj = new Database();
            DataTable dtObj = databaseObj.getMatches(name);
    
            string result = "<table  border='1' cellspacing='2' cellpadding='2' >" +
                                                "<tr>" +
                                                    "<td><b>Name</b></td>" +
                                                    "<td><b>Company Name</b></td>" +
                                                    "<td><b>Phone</b></td>"+
                                                 "</tr>";
    
            for (int i = 0; i < dtObj.Rows.Count; i++)
            {
                result += "<tr> <td><a href=\"javascript:link('" + dtObj.Rows[i][0].ToString().Trim() + "','" +
                 dtObj.Rows[i][1].ToString().Trim() +"','"+dtObj.Rows[i][2]+ "');\">" + Convert.ToString(dtObj.Rows[i]["name"]) + "</td>" +
                    "<td>" + Convert.ToString(dtObj.Rows[i]["customerCompany"]) + "</td>" +
                    "<td>"+Convert.ToString(dtObj.Rows[i]["Phone"])+"</td>"+
                 "</tr>";
            }
    
            result += "</table>";
            return result;
        }

    Here above code is written in .aspx.cs page. Database is another class. In showResult() function I've called javascript's link() function. Result is displayed in the form of table.

    0 讨论(0)
  • 2020-12-31 01:19

    You should really use the Literal ASP.NET control for that.

    0 讨论(0)
  • 2020-12-31 01:20

    You can go with the literal control of ASP.net or you can use panels or the purpose.

    0 讨论(0)
  • 2020-12-31 01:27

    Use a literal control and write your html like this:

    literal1.text = "<h2><p>Notify:</p> alert</h2>";
    
    0 讨论(0)
提交回复
热议问题