Reputation: 790
I'm fairly new to the whole ASP.NET and I'm struggling to get the html to load my functions.
So I have this basic ASP.NET Web Form that I used, when I click on "Click this" it should show the connection string but I have no idea as to what I'm doing wrong.
I currently have this in the Default.aspx:
<a ID="MyAnchor"
OnServerClick="Page_Load"
runat="server">
Click This
</a>
And this in the Default.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
}
I'm guessing I'm not really updating the text in the html since I'm not doing anything with my connectionString, am I right?
How can I let it update the text then?
Thanks in advance!
Upvotes: 0
Views: 186
Reputation:
I'm guessing I'm not really updating the text in the html since I'm not doing anything with my connectionString, am I right?
That's right. It would be pretty bad if every local variable were implicitly placed in the generated HTML.
How can I let it update the text then?
You named your element MyAnchor
, which should let you access that element by name in your C# code. You can set its InnerText
property.
If you want to display the text somewhere else, place another control somewhere else, and set the text of that instead.
Note: you may want to use the asp:*
controls (such as asp:HyperLink
), which are typically a bit easier to manipulate code-wise.
Upvotes: 1