0

Can I get a button or anchor written in pure HTML (with no runat=server) from my backend C# code?

I mean, my button is in aspx page and I want to get the button in aspx.cs page.

1
  • 1
    Apparently No. What's the reason you want to access it from code behind? If you wanted to access it from code behind whats the point of making it as pure html button Commented Jun 16, 2015 at 9:17

3 Answers 3

2

No you cannot get html controls not decorated with runat="server"in code-behind.
The FindControl method also works for only those controls that are marked runat="server".

Sign up to request clarification or add additional context in comments.

Comments

1

I think you can do it by using jquery ajax and webmethod like below

write in aspx page below code on button click

<script language="javascript" type="text/javascript"> 
$(document).ready(function() 
{
 $("#btnGetHTML").click(function()
   {
       $.ajax({
                url: "YourPAge.aspx/GetHTML",
                type: "POST",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (data) 
                         {
                              //You will get html code here 
                              alert("success: " + data.d); 
                         },
                failure: function (data) 
                         {
                                alert("Failure : " + data.d);
                         },
                error: function (data) 
                        {
                                alert("Error3 : " + data.d);
                         }
         });
   }
}
</script>

aspx.cs code

[WebMethod]
public static string GetHTML()
{
  string html="<html><body></body></html>" 
  return html; 
}

Comments

0

I've always believed it was there more for the understanding that you can mix ASP.NET tags and HTML Tags, and HTML Tags have the option of either being runat="server" or not. It doesn't hurt anything to leave the tag in, and it causes a compiler error to take it out. The more things you imply about web language, the less easy it is for a budding programmer to come in and learn it. That's as good a reason as any to be verbose about tag attributes.

the importance of is more for consistency and extensibility.

If the developer has to mark some tags (viz. ) for the ASP.NET Engine to ignore, then there's also the potential issue of namespace collisions among tags and future enhancements. By requiring the attribute, this is negated.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.