Showing posts with label creating. Show all posts
Showing posts with label creating. Show all posts

Thursday, March 22, 2012

TextBox

I am creating a back office shopping cart where the customer service can take orders over the phone. IN the web application because customer service will be using it so often that I want to give an option of quickly adding rows with 2 empty textboxes. One for Item# or product# and one for quantity with default value 1. On click on the quick add button...it should create 3 rows with each row containing the textboxes I described above. Which is the best approach. is there a sample code I can get from somewhere. I tried lot of online search but no luck. I need help on it fast. Please help.

Two possible approaches. I prefer the first

Option 1. in your layout, add the needed rows, make them actual table rows. you will add runat=server to the rows and give them an id. When you need them to be visible simply do a postback with the add rows button and make them visible when you need them.

If you need to do it without a postback, simply hide / show them using javascript instead of running the <tr> on the server

Option 2

add a placeholder where you need the textboxes to be and then add the textboxes in the code. Here is a sample.

private void AddTextBox(int TextBoxNumber)
{
txtItem = new TextBox();
txtItem.ID = "txtItem" + TextBoxNumber.ToString();
thePlaceHolder.Add(txtItem);
}


I thought about the option 1. But what if the customer service wants to add more records. I don;t want to restrict the textbox instead have them request as they need. I tried using the second option and on the button click I do get 3 rows of text boxes but if I try to click the button again it doesn;t add more textbox after the 3 was already added. Does that make sense? let me know I will try and re phrase the question.


This post shows you how to dynamically add rows to a table server-side:

http://forums.asp.net/thread/1264968.aspx

NC...


You must re-add the controls on each subsequent post-back. To do this, you will need a counter, and you will need a method that will add the number of textboxes in the counter.

example: create a label on the page and set the value = 0 and visible = false. This will be your counter.

create a method that runs in page_load that creates the same number of textboxes in your counter. When you click to add a textbox, increment your counter and add your new text box. Viewstate will still remember the values in the textboxes.


I am really new to this. Could you possibly provide me a sample code. Thanks.


Thanks for the pseudocode. It worked. Now I have another question. ON similar lines to the previous one, How do I create a table or table row with two text boxes in each row (in 2 different columns) based on button click. Any suggestions.

The link that I posted earlier shows exactly how to do that.

NC...


Here is the code sample and it gives me an error on the highlighted code in dark gray , saying "Value of type 'System.Web.UI.WebControls.TableRow' cannot be converted to 'System.Data.DataRow'. Help Please

Id. is the a number that passsed in this function. It is the counter which occurs on the click of the button

------------------

Dim

iAsInteger = 0DoWhile (i < dynamicTable.Rows.Count)Dim dataRowAs DataRow

DataRow = dynamicTable.Rows(i)

Dim newRowAs TableRow =New TableRowDim newCell00As TableCell =New TableCellDim textboxesAsNew TextBox

textboxes.ID =

"ProductId" + Id.ToString()

textboxes.Width = Unit.Pixel(32)

Dim literalControlAsNew LiteralControl

literalControl.Text =

"<p>"

form1.Controls.Add(literalControl)

form1.Controls.Add(textboxes)

Dim newCell01As TableCell =New TableCellDim textboxes1AsNew TextBox

textboxes.ID =

"ITemId" + Id.ToString()

textboxes.Width = Unit.Pixel(32)

Dim literalControl1AsNew LiteralControl

literalControl.Text =

"<p>"

form1.Controls.Add(literalControl)

form1.Controls.Add(textboxes)

newRow.Cells.Add(newCell00)

newRow.Cells.Add(newCell01)

Me.dynamicTable.Rows.Add(newRow)

i = (i + 1)

Loop


Duplicate post -- Please don't do that.

http://forums.asp.net/thread/1264968.aspx

NC...

Tuesday, March 13, 2012

Textbox - additional features?

I'm dynamically creating some textboxes but also need to add some javascript
into them. What properties do I use to do this?

txtTextBox = New TextBox
txtTextBox.ID = "CAS" & dv(cnt)("InvID")
txtTextBox.Text = dv(cnt)("Cash")
txtTextBox.Columns = 9
plhResults.Controls.Add(txtTextBox)

I need to add: onfocus="DoMyFunc();"

Thanks.txtTextBox.Attributes.Add("onfocus","DoMyFunc();")

"Rob T" <RTorcellini@.DONTwalchemSPAM.com> wrote in message
news:uzbLDha8EHA.1408@.TK2MSFTNGP10.phx.gbl...
> I'm dynamically creating some textboxes but also need to add some
javascript
> into them. What properties do I use to do this?
> txtTextBox = New TextBox
> txtTextBox.ID = "CAS" & dv(cnt)("InvID")
> txtTextBox.Text = dv(cnt)("Cash")
> txtTextBox.Columns = 9
> plhResults.Controls.Add(txtTextBox)
> I need to add: onfocus="DoMyFunc();"
> Thanks.
Nevermind...found it:

txtTextBox.Attributes.Add("onfocus", "DoMyFunc();")

"Rob T" <RTorcellini@.DONTwalchemSPAM.com> wrote in message
news:uzbLDha8EHA.1408@.TK2MSFTNGP10.phx.gbl...
> I'm dynamically creating some textboxes but also need to add some
> javascript into them. What properties do I use to do this?
> txtTextBox = New TextBox
> txtTextBox.ID = "CAS" & dv(cnt)("InvID")
> txtTextBox.Text = dv(cnt)("Cash")
> txtTextBox.Columns = 9
> plhResults.Controls.Add(txtTextBox)
> I need to add: onfocus="DoMyFunc();"
> Thanks.
txtTextBox.Attributes.Add ("onFocus", "DoMyFunc();")

"Rob T" <RTorcellini@.DONTwalchemSPAM.com> wrote in message
news:uzbLDha8EHA.1408@.TK2MSFTNGP10.phx.gbl...
I'm dynamically creating some textboxes but also need to add some javascript
into them. What properties do I use to do this?

txtTextBox = New TextBox
txtTextBox.ID = "CAS" & dv(cnt)("InvID")
txtTextBox.Text = dv(cnt)("Cash")
txtTextBox.Columns = 9
plhResults.Controls.Add(txtTextBox)

I need to add: onfocus="DoMyFunc();"

Thanks.
Add the function to the attribute collection.

txtTextBox.Attributes.Add( "onfocus", "javascript: DoMyFunc();" );

HTH,

bill

"Rob T" <RTorcellini@.DONTwalchemSPAM.com> wrote in message
news:uzbLDha8EHA.1408@.TK2MSFTNGP10.phx.gbl...
> I'm dynamically creating some textboxes but also need to add some
javascript
> into them. What properties do I use to do this?
> txtTextBox = New TextBox
> txtTextBox.ID = "CAS" & dv(cnt)("InvID")
> txtTextBox.Text = dv(cnt)("Cash")
> txtTextBox.Columns = 9
> plhResults.Controls.Add(txtTextBox)
> I need to add: onfocus="DoMyFunc();"
> Thanks.

Textbox - additional features?

I'm dynamically creating some textboxes but also need to add some javascript
into them. What properties do I use to do this?
txtTextBox = New TextBox
txtTextBox.ID = "CAS" & dv(cnt)("InvID")
txtTextBox.Text = dv(cnt)("Cash")
txtTextBox.Columns = 9
plhResults.Controls.Add(txtTextBox)
I need to add: onfocus="DoMyFunc();"
Thanks.txtTextBox.Attributes.Add("onfocus","DoMyFunc();")
"Rob T" <RTorcellini@.DONTwalchemSPAM.com> wrote in message
news:uzbLDha8EHA.1408@.TK2MSFTNGP10.phx.gbl...
> I'm dynamically creating some textboxes but also need to add some
javascript
> into them. What properties do I use to do this?
> txtTextBox = New TextBox
> txtTextBox.ID = "CAS" & dv(cnt)("InvID")
> txtTextBox.Text = dv(cnt)("Cash")
> txtTextBox.Columns = 9
> plhResults.Controls.Add(txtTextBox)
> I need to add: onfocus="DoMyFunc();"
> Thanks.
>
Nevermind...found it:
txtTextBox.Attributes.Add("onfocus", "DoMyFunc();")
"Rob T" <RTorcellini@.DONTwalchemSPAM.com> wrote in message
news:uzbLDha8EHA.1408@.TK2MSFTNGP10.phx.gbl...
> I'm dynamically creating some textboxes but also need to add some
> javascript into them. What properties do I use to do this?
> txtTextBox = New TextBox
> txtTextBox.ID = "CAS" & dv(cnt)("InvID")
> txtTextBox.Text = dv(cnt)("Cash")
> txtTextBox.Columns = 9
> plhResults.Controls.Add(txtTextBox)
> I need to add: onfocus="DoMyFunc();"
> Thanks.
>
txtTextBox.Attributes.Add ("onFocus", "DoMyFunc();")
"Rob T" <RTorcellini@.DONTwalchemSPAM.com> wrote in message
news:uzbLDha8EHA.1408@.TK2MSFTNGP10.phx.gbl...
I'm dynamically creating some textboxes but also need to add some javascript
into them. What properties do I use to do this?
txtTextBox = New TextBox
txtTextBox.ID = "CAS" & dv(cnt)("InvID")
txtTextBox.Text = dv(cnt)("Cash")
txtTextBox.Columns = 9
plhResults.Controls.Add(txtTextBox)
I need to add: onfocus="DoMyFunc();"
Thanks.
Add the function to the attribute collection.
txtTextBox.Attributes.Add( "onfocus", "java script: DoMyFunc();" );
HTH,
bill
"Rob T" <RTorcellini@.DONTwalchemSPAM.com> wrote in message
news:uzbLDha8EHA.1408@.TK2MSFTNGP10.phx.gbl...
> I'm dynamically creating some textboxes but also need to add some
javascript
> into them. What properties do I use to do this?
> txtTextBox = New TextBox
> txtTextBox.ID = "CAS" & dv(cnt)("InvID")
> txtTextBox.Text = dv(cnt)("Cash")
> txtTextBox.Columns = 9
> plhResults.Controls.Add(txtTextBox)
> I need to add: onfocus="DoMyFunc();"
> Thanks.
>

TextBox = database call. How?

I am reasonably competent at creating SqlDataSources, DropDownLists, GridViews etc. but I am drawing a blank as to how a TextBox would make a call to a SqlDataSource. Can a TextBox have a data source? How do you construct the code behind to execute a call to a database and then load a field value into the TextBox. Something like below?

protectedvoid DropDownList1_SelectedIndexChanged(object sender,EventArgs e)
{
lblCCG_ID.Text =Convert.ToString(DropDownList1.SelectedValue);
- - - run call to database - - - Select Field3 Where Field6 = @dotnet.itags.org.CCG_ID;
TextBox1.Text = Eval("Field3");

- - -

}

Yes you can databind a TextBox but not like GridView or DataList for e.g. here is one way to do it.

//Declaratively - assume LoadValueFromDB() is a code behind method to retrieve data returns a string
//Instead of LoadValueFromDB method you could databind using a Datasource e.g. a custom object e.g. Order.OrderTotal.ToString()

<asp:TextBox id="Text1"Text="<%# LoadValueFromDB()%>"Width="200px"runat="server"/>
Also see thishttp://www.developerfusion.co.uk/show/4410/5/
Well you can call the db value at the text box text as:

text='<%# DataBinder.Eval(Container.DataItem, "commentID") %>' Well you can call the db value at the text box text as:text='<%# DataBinder.Eval(Container.DataItem, "commentID") %>'