开发者

Accessing html controls within an #include html file, from server side c#

Following code is an example, I just want to know if this can be done.

I have an test.aspx file with this server side include tag;

<!--#include file="listOfCountries.htm" -->

Within listOfCountries.htm, I have:

<html>
<div>
<select id="countryList" runat="server">
<option></option>
...
</select>
</div>
</html>

Now开发者_如何学Go, Is there a way to access "countryList" in test.aspx.cs file ?

On another note, say I didn't have the #include "Countries.htm" in test.aspx, is it possible to access the controls within Countries.htm from test.aspx.cs ? (i.e. accessing an external html file controls in cs)


As far as I'm aware, what you're asking for isn't possible as the include file isn't actually parsed as asp.net.

What you want to do is create a "User Control" by right clicking on your project, choosing "Add new Item" and choosing "Web User Control" from the window that appears.

Within your user control you can define the markup for "countries.htm", and then expose the contents of the <select> to your C# code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜