简体   繁体   中英

Add Link Button in specific location

My current scenario is I retrieved the HTML of a page using the following method.

 readStream = New StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet))
 Dim fullString As String = readStream.ReadToEnd()

I did further formatting of the HTML before setting it to the innerHtml of my div .

 displaystring = Regex.Replace(fullString, "<div.*?>", "<div>")
 displaystring = Regex.Replace(fullString, "<span.*?>", "<span>")
 displaystring = Regex.Replace(fullString, "<table.*?>", "<table>")

For example, I have a part of HTML code which is

<a>Brazil</a>

And I have tried fullstring = Regex.Replace(fullstring, "<a>Brzail</a>", <asp:Linkbutton name="lnkTest" runat="server") . And I realized it cannot work because ASP controls cannot be appended as string .

How can I control.Add just after <a>Brazil</a> ? Any other suggestions are welcome too.

You cannot add ASP.Net Server control like this. You can use html control anchor tag or button and on click of this you can make an AJAX call. Sample code will be like this

fullstring = Regex.Replace(fullstring, "<a>Brzail</a>", "<a href='#' onclick='clickMe'>Link</a>") 

In Server side C# you can write a page method like `

[PageMethod]
public static string MyMethod()
{
//Your logic
  return "";
}

` In javascript

function cickMe()
{
    $.ajax({
      url: "Sample.aspx/MyMethod",
        success: function(data){
        //your logic
      }
    });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM