473,378 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to get dynamic textbox control value at runtime ????

20
Hello friends ,

I have a textbox control whose property is set to enable=false.
I want that the id should be displayed automatically incrementing the last value which is stored in database.The user cannot enter the value.

Id (int 4) IDENTITY = yes +1

I m working in ASP.NET with C# and SQL SERVER 2005
and using the sqldatasource to store the data.
Apr 10 '07 #1
9 4373
RedSon
5,000 Expert 4TB
All you should need to do is programatically set the text property to whatever value that you want it to display. Have you tried this?
Apr 10 '07 #2
sheenaa
20
All you should need to do is programatically set the text property to whatever value that you want it to display. Have you tried this?
Actually i want the value of the id which is not constant for all the time.
It changes.
Suppose at this time i run it is C1
Next time it should be C2
then again......... C3

So,how to set that value and display it in the textbox which is enabled ??
I have used the stored procedure for insert,select query
Apr 10 '07 #3
nmsreddi
366 256MB
Hello

What actually you mean id is ,is that id of your control(text box ) ,how can an id of a control change dynamically,with knowing the id ofthe control how can you access that control first,

i dint get your requirement actually ,try to post more clearly

Good Luck
Apr 11 '07 #4
RedSon
5,000 Expert 4TB
Yes, the ID should remain static and it is determined at development time. So I am not sure what you are trying to do.
Apr 11 '07 #5
sheenaa
20
No,ur understanding is wrong...
I m not able to explain my question properly sorry...

ASP.NET with C# 2005 code

Expand|Select|Wrap|Line Numbers
  1.  <body>
  2. <form id="form1" runat="server">
  3. <div>
  4. Id   
  5. <asp:TextBox ID="tbid" runat="server" Enabled="False"></asp:TextBox>
  6. <br />
  7. Address   
  8. <asp:TextBox ID="tbaddress1" runat="server" Rows="4" TextMode="MultiLine" ></asp:TextBox>
  9. <br />
  10.  
  11. <asp:Button ID="cmdview" runat="server" Text="View" OnClick="cmdview_Click" />
  12. <br />
  13.  
  14. <asp:SqlDataSource ID="SqlDataSource1" runat="server"
  15. ConnectionString="<%$ ConnectionStrings:addresstable%>"
  16. ProviderName="System.Data.SqlClient"
  17. Selectcommandtype="StoredProcedure" SelectCommand="addressSelect "
  18. </asp:SqlDataSource>
  19.  
  20. <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" autogeneratecolumns="false"
  21. AutoGenerateDeleteButton="false" AutoGenerateEditButton="false"
  22. DataKeyNames=id>
  23.  
  24. <Columns>
  25. <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
  26. <asp:boundfield datafield="id"
  27. readonly="True"
  28. headertext="ID"/>
  29. <asp:boundfield datafield="address"
  30. headertext="Address"/>
  31. </Columns>
  32.  
  33. </asp:GridView>
  34.  
  35. </div>
  36. </form>
  37. </body>
  38.  
  39.  
  40. protected void Page_Load(object sender, EventArgs e)
  41. {
  42. GridView1.Visible = true;
  43.  
  44.  
  45.  
Stored Procedure

Expand|Select|Wrap|Line Numbers
  1.  
  2. ALTER PROCEDURE insertquery1
  3.  
  4. @id Int output,
  5. @address varchar(30)
  6.  
  7. AS
  8.  
  9. if not exists (Select address from addresstable where address=@address and id <> @id)
  10.  
  11. begin 
  12.            select @id = isnull(max(id),0) + 1 from addresstable
  13. INSERT INTO addresstable
  14.                     ( address)
  15. VALUES     (@address)
  16.                 Print ' Address are now recorded'  
  17. end
  18.  
Apr 12 '07 #6
sheenaa
20
Yes, the ID should remain static and it is determined at development time. So I am not sure what you are trying to do.
The above code is just a sample which may help now to answer my question i suppose...if anything missing then let me know again...

Ok,now i want to display the 2fields in gridview i.e. ID and Address..which i will insert thru the insert parameters

Expand|Select|Wrap|Line Numbers
  1.  
  2.  <asp:Button ID="cmdsubmit" runat="server" Text="Submit" OnClick="cmdsubmit_Click" />&nbsp;
  3.  
  4.  
  5.  protected void cmdsubmit_Click(object sender, EventArgs e)
  6.     {
  7.        SqlDataSource1.InsertParameters["address"].DefaultValue =tbaddress.Text;
  8.  
  9.  
  10.        HOW TO MAKE THE LABEL/TEXTBOX DISPLAY WHICH IS ENABLED IN THE PROPERTY AND WHICH IS AUTOINCREMENT WITH IDENTITY THRU STORED PROCEDURE OF SQL SERVER 2005  
  11.  
  12.         SqlDataSource1.Insert();
  13.         GridView1.Visible = true;
  14.      }
  15.  

HOW TO MAKE THE LABEL/TEXTBOX DISPLAY WHICH IS Enabled="False" PROPERTY AND WHICH IS AUTOINCREMENT WITH IDENTITY THRU STORED PROCEDURE OF SQL SERVER 2005.

I don't want the user manually inserts the id as it is autoincrement but at the time of entering the address he can know the id and see it in the enabled textbox.If it's possible to display in the label then also it's fine..

Hope this time anyone can understand what i want and explain me..
thanxs
Apr 12 '07 #7
Plater
7,872 Expert 4TB
It looks to me that the confusion comes from the term "id", when you say "id" you are refering to a datafield in your SQL table, and not the ID associated with controls (i.e. "tbid")
Now, you want the value of the datafield "id" to be generated in code, and not by the person entering things into your webpage. It appears that your procedure handles creating a new entry in your table with the next available "id" number (i.e. if the last highest id was "12" then you insert an entry with the value of "13")
Setting the textbox enabled="false" would be correct.

Here is when I get fuzzy.
When a person loads the page, they will see two blank textboxes (one is tbid which they can't edit and the other is ready for them to type an address in), a button they can click and a list of all the addresses already in the table (your gridview thing).

Where is the problem? You want, on page load, the tbid textbox to show a number and that number will be the id that would get used if they submit a new address? If so, just make another procedure that returns the next available id number and in the page_load() function, set tbid.Text to that value?

I would recomend you set the "id" datafield to "autoincriment" (or similar) in your database. Let the database handle it. If more then one person submits an address at the same time. Each will think they are making an address for "id"=13, but one will happen first and be 13 and the other will happen second and be 14. So each thought they created address id=13, but really one will be id=14

I hope that makes sense and/or is helpful.
Apr 12 '07 #8
nmsreddi
366 256MB
Hello

i hope i got your point ,

you want to increment the value of a textbox each time user clicks the button or when some event raises and the textboxshould be read only so that user cannot edit

if that is the case you can easily do this by using a global variable from global.asax,just get the latest value from the database and assign that value to the global variable (what ever may be the name of variable) ,make sure in button click event you should increment the variable value and at the same time also update the value in global.asax

so that each time your variable contains the max (latest ) value ,then that be incremented ,now assign thisvalue to the textboxtext property

Hope you got the point, try it out

Good Luck
Apr 14 '07 #9
sheenaa
20
Hello

i hope i got your point ,

you want to increment the value of a textbox each time user clicks the button or when some event raises and the textboxshould be read only so that user cannot edit

if that is the case you can easily do this by using a global variable from global.asax,just get the latest value from the database and assign that value to the global variable (what ever may be the name of variable) ,make sure in button click event you should increment the variable value and at the same time also update the value in global.asax

so that each time your variable contains the max (latest ) value ,then that be incremented ,now assign thisvalue to the textboxtext property

Hope you got the point, try it out

Good Luck
ya nmsreddi...u r right i want to do as u got only...
Can u suggest me how to do...
how to increment the value on the enabled textbox or label...

Expand|Select|Wrap|Line Numbers
  1. select @id = isnull(max(id),0) + 1 from addresstable. 
  2.  
  3. <SelectParameters>
  4.         <asp:QueryStringParameter
  5.             Name="Id"
  6.             QueryStringField="id" />
  7. </SelectParameters>
  8.  
Pls tell me how to display it using sqldatasource with some event from the database...

Hope to get a reply from u to get me an idea...

Thanxs if u reply...in advance then...
Apr 17 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: krs | last post by:
I am using XML/XSL to build a dynamic asp.net control at runtime. So the result of the XML/XSL transformation may result in a string such as: <asp:TextBox id="TextBox1" runat="server">...
2
by: charliewest | last post by:
I need to create textboxes in real-time, the actual number of which is determine by a result from a database query. I have been able to create the controls, and then add them to the ASPX page....
1
by: sleigh | last post by:
Hello, I'm building a web application that will build a dynamic form based upon questions in a database. This form will have several different sections that consist of a panel containing one to...
3
by: RSB | last post by:
Hi Every one Having tuff time creating web controls Dynamically. All i am trying to do is read a table and generate a list of ASP TEXT Box. So how do i create this Control dynamically and where...
1
by: Tim::.. | last post by:
Can someone please tell me how I progromatically repeat the following html in a webform according to a selection made from a dropdownlist. EG: If i choose the value 2 from a dropdownlist it...
2
by: dawg1998 | last post by:
I have a page that creates dynamic textboxes based on the number of fields a user chooses to fill out. This process worked great when the page was standalone. However, when I move to a...
0
by: Mike Collins | last post by:
I have a form where I create dynamic controls at runtime. With this, I am adding a dynamic required field validators to each control as needed, but the validators are not firing when I click...
3
by: Andreas Wöckl | last post by:
Hi Group! I have a web form that is created dynamically - so I create Textboxes, RadioButtonLists, CheckBoxLists and so on - I have found some articles that there may be some problems with...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.