.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Adding and subtracting text boxes

Posted By:      Posted Date: October 13, 2010    Points: 0   Category :ASP.Net

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:

Imports System.Data.SqlClient
Imports System.Data

Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    End Sub
    Public Sub ClearFields()
        OperatorDropdown.SelectedIndex = -1
        exceptiondateInput.Text = ""
        starttimeInput.Text = ""
        endtimeInput.Text = ""
        durationInput.Text = ""
        code.SelectedIndex = -1
        Approvedby.SelectedIndex = -1
    End Sub
    Public Sub InsertRow()
        Dim myConnectionString As String = "Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxxx;"

        Dim myConnection As New SqlConnection(myConnectionString)
        Dim commandText As String = _
        "insert into Exceptions (employeenumber, exceptiondate, starttime, endtime, duration, code, approvedby) " & _
        "values(@employeenumber, @exc

View Complete Post

More Related Resource Links

Validate mutually exclusive text boxes


Meaning only one of them can have a value, but not both.

I suspect one validation control can't handle both.


Any ideas? 

Adding starting text to a column field

I am wanting to know if there is a way you can add starting text within a field that displays within a page layout?  I have a page layout that has a field (column) called 'page summary'. What I want to do is when a content managers creates a new page based on that page layout, the text "This page contains a public notice" is automatically inserted in the page summary field and the content manager can continue typing or highlight the text and remove it. Kind of like adding a base 'Text Value' to the field (column).  I want to be able to do it without having to do custom code though.

How to eliminate html tags from text boxes

Hi all,   In my application I am using a login screen. While a new user registers he has to fill the First name and Last name. There is a user search option. The details of the users will be shown in the user details page. Some users try to add html tags like </td></tr> with first name and last name. So after rendering from DB the page alignment is breaking.   How to fix this problem??   How can I avoid html tags while entering the user details?   Please give me a solution:-   Thank You  

Problem tabbing among text boxes with AJAX

We are having a problem with a form with four text boxes. If you enter a value in the first two boxes, pressing TAB as you switch between the text boxes, the data is retained in the text box as you would expect.  However, the third and fourth text boxes won't retain any data.  This happens in IE 8 but not FireFox 3.5.  The problem won't occur if you use the mouse to switch between text boxes. The problem goes away if we remove the AJAX code, but we want to retain the AJAX code so that some other things happen without postbacks.  I can upload a sample website if that will help, but I don't see where I can upload the files. We're using Visual Studio 2010 and VB.NET in an ASP.NET project.   Protected ToolkitScriptManager1.SetFocus(TextBox2)     Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChangedEnd Sub   ToolkitScriptManager1.SetFocus(TextBox3)     Protected Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.TextChangedEnd Sub   ToolkitScriptManager1.SetFocus(TextBox4)      Protected Sub TextBox3_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox3.TextChangedEnd Sub  

Making the program make text boxes according to a num of a variabe

i have a text abox that the user need to enter a number then according to this number the program need to show text boxes

Dynamic Text Boxes Creation Problem

Hi all, I am creating 5 textboxes in a row. A new creates when user press enter in the last textbox. I have taken a hidden text field and in OnKeyDown of last textbox I am assigning the combination of last textbox Id with the table count  to the hidden field and in VB Code I am checking whether the tableCount + Last textbox Id is equal to the hidden field or not then only I am generating the new row. here is the code In JavaScript On KeyDown of remarks textfield. function funcNewRow(id,count,e) {    var e = event || evt;    var charCode = e.which || e.keyCode;    if(charCode == 13){      e = cancelKey(e);      htxtBox.value = id + count;    } }   In VB Page_load method calling getTableRow() method   if htxtBox.value = "remarks" & (Tbl.Rows.Count + ViewState("TotalClearedItems")) Then  Tbl.Rows.Add(GetTableRow(Tbl.Rows.Count + 1 + ViewState(Panel1.Controls.Add(Tbl))  Panel1.Controls.add(Tbl) htxtBox.Value = "" end if   Here I have to implement a clear functionality such as each row at last contains a check box when user click the check box and press clear button the checked rows have to deleted .   The clear button code as follows : cnt = CInt(Tbl.Rows.Count)  For i = cnt To 1 Step -1 c = Pag

Infopath browser form - odd behaviour on auto expanding multi line text boxes




I have a browser form with a multi line text box. The height is set to be AUTO. Within the client all is fine. When opened as an administrator approved form the text box automatically adds a new line for every 20 characters you type.


So if you type 40 characters without pressing enter you get 2 blank lines appear under you text that you CANNOT remove.


I have tested this on a new form with various multi line text boxes. The width setting is unimportant, the spell check setting is unimportant.


If i fix the height then the issue goes away but this is not any good.


I cannot use rich text boxes as i have around 40 text boxes on the form and if they are rich text they take around 10 minutes to load in the browser (this is another issue i have)


Thanks in advance



Maxlength & Regular Expressions for text boxes


So over here, I'd asked about Regex and methods of limiting user input in text boxes, and got some very good answers, but I've hit another snag.

1) Using "Maxlength=XXXX" works great for single-line text boxes, but doesn't prevent the user entering too much text in multi-line text boxes. I wouldn't mind that, but it also doesn't trigger an error to display to the user, it just doesn't let the page submit.

2) So I've been using Regular Expressions (i.e, .{0,50} ) to pop up an error message when the user enters too much text. However, there's again a problem with multi-line text boxes. Using the dot for the validation expression does not allow the user to enter line breaks. Using \r\n will allow line breaks, but that's it. I keep looking at RegEx references online, and I can't find a way to allow both. Any combination or \r\n and . that I've tried has resulted in the expression allowing only line breaks.

So my question is this - what Regular Expression should I use to allow text (any character) with line breaks? Or, is there a better/simpler way to handle this?

 Thanks a million!


Dynamically added text boxes disappears after page refresh


Dim objDatabase As New database
        Dim objAdapter As SqlDataAdapter
        Dim objDataset As New DataSet
        Dim objAdapter1 As SqlDataAdapter
        Dim objDataset1 As New DataSet
        Dim objAdapter2 As SqlDataAdapter
        Dim objDataset2 As New DataSet

        objAdapter = New SqlDataAdapter("SELECT first_name + ' ' + last_name as [Name],father_mobile_no as [Father Mob No],mother_mobile_no as [Mother Mob No] FROM student_data WHERE class='" & cmb_class.SelectedValue & "' and division = '" & cmb_division.SelectedValue & "' and school_id='" & Session("school_id") & "'", objDatabase.con)
        objAdapter.Fill(objDataset, 0)
        If objDataset.Tables(0).Rows.Count > 0 Then

            Dim dt_table As DataTable

text boxes in grid view


how can i set a gridview with minimum 10 rows having three colums with textboxes in every colun to add a value in table with a single clikc.like entry of marks of students in a particular class.with one coloun for entering student name and other two coloun for min and max marks.how can genrate a new row dynamically to grid view for entering more data durin run time  

Correct Way to Insert Data from Text Boxes on ASPX page into SQL Database Using VB


Please help me, I have been trying this for a week now and this is how far I have gotten.


I am new to this, and I am using MS Visual Web Developer Express.


OK - This is what I have come up with, but when I run it I get the following error  (I decided to just try to use a simplified table just to get an understanding of the basic concepts):



Partial Class label_form
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Declaring variables
        Dim username, labelname, ownersname, address1, address2, city, state, zipcode, country, contactnumber, emailaddress, data_source, con, sql_insert

        ' Check if Necessary Text Is Missing ( will do this once I can get it to work with no empty text boxes)

        ' Get Values from TextBoxes
        username = txtUserName.Text
        labelname = txtLabelName.Text
        ownersname = txtOwnersName

Form Services 2010 - potential bug in plain text - multi-line boxes



Just wondering if anyone else has found the following and perhaps a resolution.  (Blog post with image examples here: Click)


An InfoPath Form created in Microsoft InfoPath Designer 2010 and is installed as an Administrator approved template.

  • Form Control: Text Box


  • Read-only – No
  • Enable spelling checker – Yes
  • Enable AutoComplete – Yes
  • Multi-line – Yes


  • Height: Auto

Compatibility Settings:

  • Form Type: Web Browser Form (2010)


  • Browser: Internet Explorer 7, 8, Google Chrome

When running the Form in the web and a user types into the multi-line text box; after 20 characters the text box gets bigger by 1 row.

On evaluation using the IE8 development toolbar.  It would appear that the control is rendered as a <textarea> HTML element and JavaScript runs on the 22<sup>nd</sup> character and adds 1 to the “rows” attribute of the <textarea> element.

For example:

adding static text before Bind() in datalist control


Hello, I have a datalist control

In it, I have a hyperlink that im binding the url, and the text to from a mysql database

here is my code so far

<asp:HyperLink ID="HyperLink1" runat="server"
    NavigateUrl='<%#Bind("topicid") %>' Text='<%# Bind("title") %>'></asp:HyperLink>

Now, the problem is, the field "topicid" returns a number, such as 3. I want to add the following text before it: viewTopic.aspx?id=

So, ideally, i want something like this

<asp:HyperLink ID="HyperLink1" runat="server"
    NavigateUrl='<%# "viewTopic.aspx?id=" + Bind("topicid") %>' Text='<%# Bind("title") %>'></asp:HyperLink>

But, when I do it that way, I obviously get an error.

So, is there any way to solve this problem without having to modify the database?

Thank You

Adding watermark or text to images on uploading or displaying


Is there a way to process images once uploaded to my asp.net site, to put a watermark or some text across the image to copyright the images? I would like to do this server-side if possible.

The other option I have discovered here (http://wpglamour.com/how-to-watermark-all-your-uploaded-images/) would be to store the images as they are on the server, but to manipulate the display so it appears the image is watermarked . However, this solution is in PHP. Does anyone know a good PHP to VB.NET translator?! Or does anyone have a good suggested link, idea or code? Or can I add PHP to my ASP.NET site?

How to access text boxes within Repeater control?


I have a data bound repeater with varying (but limited) number of rendered rows, depending on records retrieved.

There are several text boxes in the repeater for each row.  If I wanted to change text formatting in a text box on lost focus, how do I know what the textbox is going to be named?  I am guessing its going to look something like this: "ctl00_contentPlacer_rptPunches_ctl02_txtPunchIn1", but with unpredictable number of rows, don't know how to proceed.

Assume I know very little JavaScript.

Adding a node to XML stored as a text column

I have a table which has the following structure:



TABLE [Configuration].[t_Configurations](
[Settings] [text] NOT NULL,
[Machine] [varchar](128

Adding math symbols to a label text



I have to display math symbols in the label text for checkbox.

I have created the symbol in MSWord but dont know how is can do that in the website.Is there anyway I can do that.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend