dynamic-controls

ASP.NET WebControl & Page - Adding controls (like TextBox) dynamically

被刻印的时光 ゝ 提交于 2019-12-11 05:35:23
问题 I'm trying to create a custom server control (WebControl) with a text box. I add asp.net textbox to the custom control in CreateChildControls override. In OnInit override I add event handler to TextBox.TextChanged. Everything works, except that TextChanged never fires. I looked at viewstate and it looks like my textbox never saves its Text property in the viewstate. I've tried to set Text in various places, including constructor, but nothing works. How can I get TextBox dynamically added to

Dynamically generated Controls ID returned as NULL

喜夏-厌秋 提交于 2019-12-11 00:28:53
问题 I am able to create dynamic controls in Page_PreInit() function. 'How to retrieve the control and its ID' My C# code to create one of the DynamicControls var btn = new WebForms.Button(); btn.Text = "+"; btn.ID = "Addmore"; btn.Click += new System.EventHandler(AddMoreSearchFields); I am using the below piece of code to find which controlid is clicked. string eTarget = Request.Params["__EVENTTARGET"].ToString(); **eTarget is always "" NULL** protected void Page_PreInit(object sender, EventArgs

Show the picture from database to each usercontrol's picturebox?

此生再无相见时 提交于 2019-12-08 12:18:45
问题 Usercontrol Code: private string lastName; public string LastName { get { return lastName; } set { lastName = value; textBox1.Text = value; } } Form Code: using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString)) { myDatabaseConnection.Open(); using (SqlCommand SqlCommand = new SqlCommand("Select LastName, Image from Employee", myDatabaseConnection)) { int i = 0; SqlDataReader DR1 = SqlCommand.ExecuteReader(); while (DR1.Read()) { i++; UserControl2

Dynamic button click event not able to call a function vb.net

北慕城南 提交于 2019-12-08 11:05:28
问题 The TabLoad() function doesn't seem to be working on clicking of this dynamic button. The aim of this button click event is that it deletes text from a text file and loads the form again. Below is the complete code. The TabLoad() function is in the NextDelbtn_Click sub at the end. Also any suggestion regarding change of code is appreciated. Imports System.IO Public Class Form1 Dim str As String Dim FILE_NAME As String = "D:\1.txt" Dim file_exists As Boolean = File.Exists(FILE_NAME) Private

How to name and find dynamically created webcontrols in c#

微笑、不失礼 提交于 2019-12-08 08:46:58
问题 I am trying to add a unique name to each textbox that I'm adding to a table. I've tried: TableRow someRow = new TableRow(); TableCell someCell = new TableCell(); TextBox someTextbox = new TextBox(); someTextbox.Attributes.Remove("name"); someTextbox.Attributes.Add("name",itsId); someCell.Controls.Add(someTextBox); someRow.Cells.Add(someCell); theTable.Rows.Add(someRow); The html generated includes both my name and the autogenerated name as attributes of the textbox. Unfortunately, when I run

Can't Find Controls in GridView on Dynamic Controls

跟風遠走 提交于 2019-12-02 10:34:32
I have a gridview where I add textboxes to everycell on runtime. However, I can't seem to access those controls using findcontrol Here is how I add the textboxes to the gridview: If e.Row.RowType = DataControlRowType.DataRow Then For i = 1 To e.Row.Cells.Count - 1 Dim txtSchedule As New TextBox() txtSchedule.ID = "txtSchedule" & i.ToString e.Row.Cells(i).Controls.Add(txtSchedule) Next End If When I go to find the controls it says they are Nothing : GridView1.Rows(0).Cells(cellindex).FindControl("txtSchedule" & cellindex.ToString) EDIT The problem is that after the textboxes get populated it

Dynamic Event Handler not Firing

戏子无情 提交于 2019-12-01 23:17:14
问题 I want to create an amount of controls dynamically based on a number the user enters into a textbox. This part I have working fine, but I also need the dynamically created textboxes to have event handlers of their own, so the user can enter a number into them, and have more controls created. My problem is that the event handler I've setup for these controls to use does not fire. Maybe I'm not understanding the ASP.NET page life cycle correctly, but I am currently having the dynamic controls

Pre-init function not finding all dynamic controls

牧云@^-^@ 提交于 2019-12-01 14:57:59
My scenario : I have 3 radio button. when clicked each one of them show different set of textboxes and a button are created dynamically. My Problem is when i clicked on the button i lose all the dynamically created controls. i eventually found out to initialize the dynamic control on Page_Preinit as below. protected void Page_PreInit(object sender, EventArgs e) { List<string> keys = Request.Form.AllKeys.Where(key => key.Contains("txtDynamic")).ToList(); int i = 1; foreach (string key in keys) { TextBox CPDT = new TextBox(); CPDT.ID = "test" + i.ToString(); CPDT.CssClass = "form-control"; Label

ASP.net Dynamically adding controls on Button press. Postback issue

放肆的年华 提交于 2019-12-01 13:24:05
I have a user control which contains several buttons, depending on the button pressed a different control is added to the page (lets say button 1 adds a TextBox, button2 adds a label). I have code along the lines of: protected void but1_click(object sender, EventArgs e) { TextBox tb = new TextBox(); tb.ID = "tb1"; paramsCtrlDiv.Controls.Add(tb); } protected void but2_click(object sender, EventArgs e) { Label lb = new Label(); lb.ID = "lb1"; paramsCtrlDiv.Controls.Add(lb); } I then have a third button (button3) to get all controls on the page and their values. (Assume each button is only

How to persist a dynamic control (c#)

久未见 提交于 2019-12-01 12:07:05
As per the title, I have created a custom control. On a certain button click event, this control is instantiated, then added to the page. It is a dynamic control, with it's own button events. In order for these button events to be triggered, the control must be drawn by the end of Page_Load / OnLoad , in the subsequent page_load / onload lifecycle stage. My problem is how do I persist this control? I cant store it in the Session object because it contains non-serializable items. You should recreate dynamic controls on every postback. The best place to do that is method CreateChildControls . To