asp.net-controls

How to add control to the page programatically in page load?

孤人 提交于 2020-01-03 13:45:29
问题 I am trying to add controls to the page from the code behind in the page load stage like this: foreach (FileInfo fi in dirInfo.GetFiles()) { HyperLink hl = new HyperLink(); hl.ID = "Hyperlink" + i++; hl.Text = fi.Name; hl.NavigateUrl = "../downloading.aspx?file=" + fi.Name + "&user=" + userIdpar; Page.Controls.Add(hl); Page.Controls.Add(new LiteralControl("<br/>")); } The error which I am getting is on Page.Controls.Add(hl) and here is the explanation: The control collection cannot be

Button ClickEvent is not triggered

徘徊边缘 提交于 2019-12-25 18:17:23
问题 Afternoon All, I have two buttons on my web page that is used to lock and unlock a web page so that a user can lock the page and edit this without other users being able to access the record and then unlock this record so other users can edit this. The problem i have is that the buttons doesnt work and im not to sure why. I am using image buttons but it looks like the event is not being triggered, i cant see the problem and its driving me crazy. Can some one please take a look at my code...

How to register custom server control on ASP.NET page

你。 提交于 2019-12-18 12:54:06
问题 I have a project and I am trying to register a custom server control (there is no .ascx file) on the page. I am currently using Class Declaration namespace MyApp.Controls{ public class CustomControl: WebControl{ public string Text { get { String s = (String)ViewState["Text"]; return ((s == null) ? String.Empty : s); } set { ViewState["Text"] = value; } } protected override void RenderContents(HtmlTextWriter output) { output.Write(Text); } } } On my page, <%@ Register TagPrefix="myControls"

Set ClientID in asp.net

情到浓时终转凉″ 提交于 2019-12-18 05:47:18
问题 Is it possible to set the ClientID of any asp.net server control? How can I do this? 回答1: The good news is that in VS 2010 .Net 4, you'll have complete control over Client IDs! Still for the current versions of .Net, you can make due. I assume you need the ID for JavaScript. If so, just get the ID like so: <script type="text/javascript"> var myTextBox = $('#<%=TextBox1.ClientID%>'); </script> 回答2: I would advice against doing this unless you are sure you want to do it, but there is a way. You

ASP.NET Server control with an additional bindable field

。_饼干妹妹 提交于 2019-12-12 08:58:06
问题 I have created a custom server control, deriving from System.Web.Contols.CheckBoxList to customize how a CheckBoxList is rendered. I also wanted to add another bindable field and get the value of the field within the CheckBoxList.RenderItem() method. The field I want to create, should contain a value specifying whether a CheckBoxListItem is checked. I've read some articles regarding custom DataFields, but it never gets explained in detail. I've included a portion of my class to better explain

Need help figuring out a way to input data into an asp:DataGrid

人盡茶涼 提交于 2019-12-11 20:32:22
问题 I have an asp:DataGrid I need to populate, and the original developer created a weird wrapper with very little flexibility, so I have decided to switch it over to a DataTable instead. The only issue is the event that it uses to populate my grid does not like my datatables. It keeps saying that it cannot convert from a DataTable to a DataRowView, which makes sense. I need help figureing a good way to pass the data from my DataTable into the dataGrid. Here is the event in question protected

Possible to have a inner control on a custom server control?

一世执手 提交于 2019-12-11 07:49:40
问题 I would like to be able to do something like: <ui:Tab Title="A nice title"> <TabTemplate> <asp:Literal runat="server" ID="SetMe">With Text or Something</asp:Literal> </TabTemplate> </ui:Tab> but also be able to do: <ui:Tab Title="A nice title"> <TabTemplate> <asp:DataList runat="server" ID="BindMe"></asp:DataList> </TabTemplate> </ui:Tab> Answer code I eventually came up with: [ParseChildren(true)] public class Node : SiteMapNodeBaseControl, INamingContainer { private ITemplate tabTemplate;

ASP.NET: explicit vs implicit localization?

ぃ、小莉子 提交于 2019-12-09 17:41:18
问题 To my mind the advantage of implicit localization over explicit localization is that if you have more than one property to localize for a given control, it's a more economical syntax. In the case where you just need to localize some text I use the asp:Localize control which only has a single property (Text) that renders to the UI. Is there a reason to use one over the other? Any style preference? Are there any speed differences? Implicit <asp:Localize ID="Localize1" runat="server" meta

ASP.NET control to render a <div>

烂漫一生 提交于 2019-12-05 08:33:11
问题 The Label control in ASP.NET seems to render <span> tags, but is there a server control to render HTML within a <div> ? Sure, I could set display: block and it might look the same, but I'd rather not be nesting divs inside spans. Also I'd prefer not to use <%= MyVariable %> because that might not behave nicely on postbacks. Any suggestions, please? 回答1: I think you need HtmlGenericControl class. It has a constructor which accepts a string variable which initializes a new instance of the

ASP.NET Server control with an additional bindable field

旧巷老猫 提交于 2019-12-04 14:57:54
I have created a custom server control, deriving from System.Web.Contols.CheckBoxList to customize how a CheckBoxList is rendered. I also wanted to add another bindable field and get the value of the field within the CheckBoxList.RenderItem() method. The field I want to create, should contain a value specifying whether a CheckBoxListItem is checked. I've read some articles regarding custom DataFields, but it never gets explained in detail. I've included a portion of my class to better explain what I can't seem to understand. public class ListedCheckBoxList : CheckBoxList { protected override