I'm trying to make a form where the text boxes and titles for each box are created dynamically based on how many array values there are. I have tried a repeater but am a little unclear on how I can get the texbox to bind to one area of and the title to bind to another. This is what I have so far:
[Code]....
...and this is the code-behind with an associated array, arr1:
// Bind Array to Repeater rep1.DataSource = arr1; rep1.DataBind();
This works and adds values where container.dataitem is but how to I make it add one set of array values there and another set of array values where the *x* is?
Using C# and SQL as the database.I have a page with a gridview and some text boxes and drop down list boxes. A user selects a record from the grid view I query the database and fill the text boxes and drop down list boxes.
Some fields get updated periodincally thus there is no data in those fields in the database until some time.
A strange thing happens.When filling data some text boxes gets a one tab spacing .
i am creating some of the control at runtime according database values. problem is that when i click onto the button, if the text box is empty, the required field validator(genrated at runtime) show first time that the text box is empty. but one agin i click on to the button, it doest show any error messege and all of the control which i am genrating at run time are hiding when i see at the page source, no control is find there.
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using AjaxControlToolkit; using click2install.controls; public partial class FeebackForm_Client : System.Web.UI.Page { HtmlGenericControl table = new HtmlGenericControl("table"); DataSet ds = new DataSet(); protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { CreateForm(); } } public void CreateForm() { ds = DBManager.ExecuteDataset("[FeedBack_FeedbackDetail_get]"); for (int i = 1; i < ds.Tables[0].Columns.Count - 1; i = i + 4) { //CreateControl(txtAddress.Text.ToString(), txtAddressRun, false, false, txtAddressToolTip.Text, txtAddressWaterMark.Text); string Name = ds.Tables[0].Rows[0][i].ToString().Replace(" ",""); if (Name != "") { TextBox txtControl = new TextBox(); //RequiredTextBox txtControl = new RequiredTextBox(); txtControl.ID = "txt" + Name; txtControl.CausesValidation = true; bool RequiredField; bool ToolTip; if (ds.Tables[0].Rows[0][i + 3].ToString() == "True") { RequiredField = true; } else RequiredField = false; if (ds.Tables[0].Rows[0][i + 1].ToString() != "") { ToolTip = true; } else ToolTip = false; string TooltipText = ds.Tables[0].Rows[0][i + 1].ToString(); string WaterMarkText = ds.Tables[0].Rows[0][i + 2].ToString(); CreateControl(Name, txtControl, RequiredField, ToolTip, TooltipText, WaterMarkText); } } HtmlGenericControl tr = new HtmlGenericControl("tr"); HtmlGenericControl td1 = new HtmlGenericControl("td"); HtmlGenericControl td2 = new HtmlGenericControl("td"); HtmlGenericControl td3 = new HtmlGenericControl("td"); HtmlGenericControl td4 = new HtmlGenericControl("td"); Button btnInsertRun = new Button(); btnInsertRun.Text = btnSubmit.Text.ToString(); btnInsertRun.ValidationGroup = "Check"; td2.Controls.Add(btnInsertRun); tr.Controls.Add(td1); tr.Controls.Add(td2); tr.Controls.Add(td3); tr.Controls.Add(td4); table.Controls.Add(tr); pnlPreview.Controls.Add(table); System.Threading.Thread.Sleep(500); ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), "Hide();", true); System.Threading.Thread.Sleep(500); ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), "ShowAddDisability()", true); } public void btnInsertRun_Click(object sender, System.EventArgs e) { CreateForm(); //ds = DBManager.ExecuteDataset("[FeedBack_FeedbackDetail_get]"); //TextBox txt1,txt2,txt3,txt4,txt5=new TextBox(); //objBox2 = this.Page.FindControl("objBox2") as TextBox; string ss = "txt" + ds.Tables[0].Rows[0][1].ToString(); //TextBox objTextBox = (TextBox)PnlControlPanel1.FindControl(strControlName); TextBox txt1 = new TextBox(); txt1 = (TextBox)this.Page.FindControl("txt" + ds.Tables[0].Rows[0][1].ToString()); //txt1=this.pnlContainer.FindControl("txt"+ds.Tables[0].Rows[0][1].ToString()) as TextBox; // txt2 = this.pnlContainer.FindControl("txt" + ds.Tables[0].Rows[0][5].ToString()) as TextBox; // txt3 = this.pnlContainer.FindControl("txt" + ds.Tables[0].Rows[0][9].ToString()) as TextBox; // txt4 = this.pnlContainer.FindControl("txt" + ds.Tables[0].Rows[0][13].ToString()) as TextBox; // txt5 = this.pnlContainer.FindControl("txt" + ds.Tables[0].Rows[0][17].ToString()) as TextBox; string fh = txt1.Text; //DBManager.ExecuteNonQuery("Feedback_FeedbackInsert", ds.Tables[0].Rows[0][1].ToString(), txt1.Text,ds.Tables[0].Rows[0][5].ToString(), txt2.Text,ds.Tables[0].Rows[0][9].ToString(), txt3.Text,ds.Tables[0].Rows[0][13].ToString(), txt4.Text,ds.Tables[0].Rows[0][17].ToString(), txt5.Text); Response.Write("Ho Gya"); } public void CreateControl(string Name, TextBox ControlID, bool RequiredField, bool Tooltip, string TooltipText, string WaterMarkText) { if (WaterMarkText == "") WaterMarkText = Name; HtmlGenericControl tr = new HtmlGenericControl("tr"); HtmlGenericControl td1 = new HtmlGenericControl("td"); HtmlGenericControl td2 = new HtmlGenericControl("td"); HtmlGenericControl td3 = new HtmlGenericControl("td"); HtmlGenericControl td4 = new HtmlGenericControl("td"); td1.InnerText = Name; ControlID.ValidationGroup = "Check"; //ControlID.ValidatorMessage = Name + " is Required Field"; //ControlID.ValidatorDisplayType = ValidatorDisplay.Dynamic; //ControlID.ValidatorEnableClientScript = true; td2.Controls.Add(ControlID); if (RequiredField == true) { //RequiredFieldValidator Valid = new RequiredFieldValidator(); //Valid.ID = "Valid" + Name; //Valid.ControlToValidate = ControlID.ID.ToString(); //Valid.ErrorMessage = Name + " is Required Field"; //Valid.Text = "*"; //Valid.Display = ValidatorDisplay.Dynamic; //Valid.EnableViewState = true; //Valid.SetFocusOnError = true; //Valid.Enabled = true; //Valid.EnableClientScript = true; //Valid.InitialValue = WaterMarkText; //Valid.ValidationGroup = "Check"; //td3.Controls.Add(Valid); } if (Tooltip == true) { HtmlGenericControl span = new HtmlGenericControl("span"); //span.Attributes.Add("class", "hotspot"); span.Attributes.Add("onmouseout", "tooltip.hide();"); span.Attributes.Add("onmouseover", "tooltip.show('" + TooltipText + "');"); HtmlImage img = new HtmlImage(); img.Src = "info.png"; span.Controls.Add(img); td4.Controls.Add(span); } //TextBoxWatermarkExtender WaterMark = new TextBoxWatermarkExtender(); //WaterMark.WatermarkText = WaterMarkText; //WaterMark.EnableClientState = true; //WaterMark.TargetControlID = ControlID.ID.ToString(); //WaterMark.Enabled = true; //WaterMark.ID = "WaterMark" + Name; //td1.Controls.Add(WaterMark); tr.Controls.Add(td1); tr.Controls.Add(td2); tr.Controls.Add(td3); tr.Controls.Add(td4); table.Controls.Add(tr); } } after rendring the page... <div id="pnlContainer"> <table><tbody><tr><td>Email</td><td><input type="text" id="txtEmail" name="txtEmail"></td><td></td><td><span onmouseover="tooltip.show('Email');" onmouseout="tooltip.hide();"><img src="info.png"></span></td></tr><tr><td>FirstName</td><td><input type="text" id="txtFirstName" name="txtFirstName"></td><td></td><td><span onmouseover="tooltip.show('First Name');" onmouseout="tooltip.hide();"><img src="info.png"></span></td></tr><tr><td>LastName</td><td><input type="text" id="txtLastName" name="txtLastName"></td><td></td><td><span onmouseover="tooltip.show('Last Name');" onmouseout="tooltip.hide();"><img src="info.png"></span></td></tr><tr><td>City</td><td><input type="text" id="txtCity" name="txtCity"></td><td></td><td><span onmouseover="tooltip.show('City');" onmouseout="tooltip.hide();"><img src="info.png"></span></td></tr><tr><td>Address</td><td><input type="text" id="txtAddress" name="txtAddress"></td><td></td><td><span onmouseover="tooltip.show('Address');" onmouseout="tooltip.hide();"><img src="info.png"></span></td></tr></tbody></table></div>
but after the click on to the button it shows only the container div..
I have a custom validator which validates three text boxes. my code is,
[Code]....
I fill in all the three textboxes.it still gives me the error message to fill in all the boxes and does not submit the page even when all the three boxes are filled.
I am creating n number of Combo boxes dynamically at run time and adding a Handler of Combo1_SelectedIndexChanged() to the combo boxes.
At run time, When I select an item from one of the Combo boxes, the event fires n times rather than 1.
So for example : If there are 5 combos created, and I select an item from my first combo, the event Combo1_SelectedIndexChanged() , fires 5 times and that is an issue for me. How can I restrict this to run only for the combo that I selected.
I have the usual problem of dynamically created usercontrols not hitting the event handler for a linkbutton inside the control, but I've checked the usual problems and I can't work out what's wrong. I'm calling a function to create the controls at the bottom of my page.load (although I did try page.init as well just in case) outside of my page.ispostback check, and I'm setting the controls id's to a fixed name which is consistent across postbacks. Any ideas what's wrong?
[Code]....
Usercontrol code:
<asp:LinkButton runat="server" ID="lnkDeleteGroup" Text="Delete this group" />
I am trying to figure out how to get the text value from each textbox on a page that has a dynamically created number of text boxes. I need to store that value in a database row. I guess what i need is to be able to store the text box values in a collection or arrary of some sort and then be able to use textbox(i).value or something of that nature. Not really sure where to begin.
I have a user control called ucTriStateButton. It raises an event when it is clicked, called TriStateButtonClicked. If I put this user control on a page, it works fine. Here is the declaration on the .aspx page:
[Code]....
When the button is clicked the method tsbTest_TriStateButtonClicked executes correctly.
The problem is when I put the user control in template field of a GridView.
[Code]....
There is no way to hook the event handler to the control in Page_Load because I cannot get a reference to tsbMorning. So I did it in the RowDataBound event handler of the GridView, where I also do a bunch of other row-specific stuff. Although this builds and runs, the event is never actually subscribed to and so never gets fired.
So the question is - how can I handle an event from many instances of the same user control within a GridView? I am calling the same bit of code regardless of which user control is actually clicked. I only need to know that one was clicked.
I added a Input (Text) control in my web form and turned it into an HTML server control so its an instance of HtmlInputText class.
If I double click on the control It only adds a OnClick event handler method inside the script tags in the HTML doc of the web form but how to I get to handle its Serverchange event exactly? does VS.net 2008 has no ability to auto wire up the event to the control, do I have to manually wire up the event handler?
While handling the Edit link button I need to use the value in the BoundField, UserName. Unfortunately during the OnRowEditing handler, all strings are empty "". This is also true in the ensuing OnRowDataBound handler for the row in question where e.Row.RowState == DataControlRowState.Edit. Is there a way to obtain this value after the user clicks on the Edit link, and commences the OnRowEditing event?
I am programatically adding a control to an aspx page and binding a server side event to an index changed event inside the control. (It's a RadListBox from Telerik's ASP.NET controls) The problem is that on the postback triggered from the control, the event doesn't hit its eventhandler because on the postback the control isn't defined. Is there a way to handle this without having to retrace the logic taken before and rebuild the controls so the events that stem from it are processed?
I created a customDropdown usercontrol with Events and It worked fine.
Now I stored the path of the ascx file in the database table and i want to Load the ascx file and handle the Events dynamically in an aspx page.
To Load the usercontrol and access the public properties and method, I need to know the object i am trying to load, right?
For Example
FeaturedDDL c = (FeaturedDDL)Page.LoadControl("~/FeaturedDDL.ascx").
But I dont want to hardcode objectType "FeaturedDDL", coz i dont have that stored in my Database field.
Since I am loading the usercontrol by getting the path and name of the usercontrol from the database table,how will I know the ObjectType at that time?
How to accomplish that and also how to handle the events for these type of situation?
I have two text boxes called starttime and endtime which are datetime sqldbtypes that I want to subtract the value to show in a duration label. I know that you can do a subtraction with datediff in t-sql to find the time difference, and I'm wondering if that's the best way to approach this. Here is the code from my default.aspx.vb page:
I'm very new to ASP.NET, how would it be possible to have a complete form with, let's say, 10 text boxes. Once the page is displayed, the user would only see the first textbox. After the user has input data into that box, the second textbox would appear. After data is input into the second textbox, the third textbox would appear and so on. I know it probably has something to do with Postback but I cannot find anything on this scenario.
I have a page that allows users to upload photos and when they click the upload button it renders a few textboxes used to change the photo's information and also the displays the photo. After they are done upload photos, they can then insert all the information in each of the textboxes. Then users click the Upload button and it takes all the information and places it in the database. The problem is that when I say "get the text from these textboxes" using the textbox IDs, it tells me that those textbox IDs are not in the current context.
I have placed the code in page_init and it submits the email with empty textboxes - the filled out information is missing. Any knows why the textboxes are blank? Here is the code:
public partial class reservation : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Response.Write("page loaded"); } protected void Page_Init() { if (Page.IsPostBack) { SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage();......................
I'm developing a web form. I use the style sheet for the page and make the font size x-small.
But I noticed all the text boxes in the page looks a little higher than expected comparing with the font of the other text in the page.
Is there an easy way to change all the height of the textboxes on the page? and make new creation of text boxes the same height as all the other controls on the page?
Also I tried to select multiple text boxes to aligh them or make the same size, I remember I can do it in visual studio 2005 before, but now I cannot do it in 2008.
I did it be select one, and press ctrl button to select the other one, but the other one cannot be selected. Did I do something wrong?
I have an ASP.NET gridview where I allow the user to edit a record. I need to validate multiple fields as one. I need to require that the user either enter a first and last name OR a company name. All three cannot be blank. Most of the sample code I am finding does not address the text boxes only being visible while the gridview is in edit mode. When not in edit mode, the text boxes do not exist so document.getElementById('<%= editFirstName.ClientID %>') throws an error upon page load.
I have 50 textboxes in a table and i would like to write a conditonal statement. If the textboxes has null or empty then i want to assign them 0 to all the textboxes.(VB.Net) I tried
i have to genrate dynamic textbox, we have a textbox in which user enter any number, when user hit genrate button the number(which user insert) of text boxes will genrate.how can i do it?