|
as per the msdn documentation, I have done this..
Dim name As TextBox = nameHolder.FindControl("txtname")
also I had done this
If (Not name Is Nothing) Then
' Get name's parent.
Dim myControl2 As Control = name.Parent
Response.Write("Parent of the text box is : " & myControl2.ID)
Else
Response.Write("Control not found.....")
End If
and its showing as control not found..
Thanks and Regards,
|
|
|
|
|
Dot Net Jantu wrote: and its showing as control not found..
Have you actually added a control to the Controls collection of nameHolder with the ID 'txtname'?
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
if this is what you mean then yes.
Dim txtname As TextBox
txtname = New TextBox
txtname.AutoPostBack = False
txtname.BackColor = Drawing.Color.AliceBlue
txtname.BorderColor = Drawing.Color.Black
nameHolder.Controls.Add(txtname)
Thanks and Regards,
|
|
|
|
|
Dot Net Jantu wrote: Dim txtname As TextBox
txtname = New TextBox
txtname.AutoPostBack = False
txtname.BackColor = Drawing.Color.AliceBlue
txtname.BorderColor = Drawing.Color.Black
nameHolder.Controls.Add(txtname)
The description of the Control.FindControl which you said you had read, is as follows:
Searches the current naming container for a server control with the specified id parameter.
You haven't set the ID property for your control. The fact that you have declared a variable called txtname and set it with a reference to your dynamically created TextBox object is not relevent.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
hey thanks it worked.
I would like to know that do i need to assign a id for the button also?
And one more thing will i have to use that find control method in each and every procedure to retrieve the vbalue of the control?
Thanks and Regards,
|
|
|
|
|
Dot Net Jantu wrote: I would like to know that do i need to assign a id for the button also?
You probably should do. You will need to if you want to locate instances of the Button control calling FindControl on the container object.
Dot Net Jantu wrote: And one more thing will i have to use that find control method in each and every procedure to retrieve the value of the control?
Yes, if you don't already have a reference to one of the controls you will need to call the FindControl method on the container object, passing in its ID to find it.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Apart from what you've already been told, the button needs to be created in the LoadViewState function so that it exists early enough in the page lifecycle for the viewstate to be restored and the event to fire.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I learning and have a problem this topic. Here is what I'm tryig to figure out in my head. I need to pass a function the name "Joe" and then have the function look it up in the database and return it back so it can go inside a text vale.
Here is the example I'm work through. I can't seem to get it to work so I need to make sure I understand how to pass arguments and return them.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim name as String = "Joe"
Dim Userid as Integer
GetUserID(name, result_sUserID)
result_sUserId = txtUserid.text
End Sub
Public Function GetUserID(ByVal name As String, result_sUserID As Integer) As Integer
.... datbase connection stuff
.... userid as int32 in database
sUserID = Convert.ToInt32(myCommand.ExecuteScalar())
Return
Result_sUserID = sUserID
End Function
Chris Stewart
www.pluginforsuccess.com
|
|
|
|
|
The second argument to GetUserID is unnecessary as your function only needs to return 1 value. Change Return to Return sUserID and remove the following line. Modify the calling code to assign the value returned by the function to a variable.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
So I do that
GetUserID(Subdomain)
'Populate lblUserId with result_sUserID
Dim sUserID As Integer
sUserID = lblUserID.Text
sUserID = Convert.ToInt32(myCommand.ExecuteScalar())
objConnection.Close()
Return sUserID
and I get the following error message:
[FormatException: Input string was not in a correct format.]
Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) +211
Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +84
[InvalidCastException: Conversion from string "" to type 'Integer' is not valid.]
Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +238
UrlCompare.Button1_Click(Object sender, EventArgs e) in C:\inetpub\wwwroot\UrlCompare.aspx.vb:34
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
Chris Stewart
www.pluginforsuccess.com
|
|
|
|
|
csinva wrote: Dim sUserID As Integer
sUserID = lblUserID.Text
sUserID = Convert.ToInt32(myCommand.ExecuteScalar())
This bit of code doesn't make any sense. Why do you assign a value to sUserID in one line and then reassign the value in the next line. Surely this is unnecessary?
I assume the code crashes on the first assignment. You can't implicitly cast a string value to an Integer. If the value of lblUserID.Text is an empty string obviously there is no numeric equivalent. You should use Integer.TryParse to perform type conversions if you don't know in advance that they will be successful.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
That's because you are trying to assign the contents of the Text property of the control to the integer variable.
This, and all the other mistakes in the code, is outlined in my other reply in this thread.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
I made corrections in the code and started to write comments, but I had to put number references in the comments, and the notes separately:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim name as String = "Joe"
Dim Userid as Integer
' 1, 2, 3
Userid = GetUserID(name)
' 4, 5
txtUserid.Text = Userid.ToString()
End Sub
' 6
Public Function GetUserID(ByVal name As String) As Integer
.... datbase connection stuff
.... userid as int32 in database
sUserID = Convert.ToInt32(myCommand.ExecuteScalar())
' 7
' Return
' 8
' Result_sUserID = sUserID
' 9
Return sUserID
End Function
1. You were trying to use the variable Userid by the name result_sUserID. If you use the same name for the same variable, you will find that the compiler is much more cooperative.
2. Sending the value of the variable Userid to the function doesn't make it possible for the function to return a value to the variable.
3. The function returns a value, you should assign that value to the variable.
4. You got it backwards. You should assign the value of the variable to the Text property of the control, not the other way around.
5. The Text property is a string value, so you should convert the integer value to a string.
6. Remove the integer argument from the function.
7. You are returning from the function before assigning a return value. The rest of the code would not be executed.
8. Assigning a value to one of the arguments of the function doesn't change the variable from where the value was taken that was sent to the function.
9. Use the Return statement to set the return value of the function.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Thanks it really helpes me out.
Chris Stewart
www.pluginforsuccess.com
|
|
|
|
|
So let me expand my understanding and figure out how to pull back more than just piece of data.
Would I then have to create a SqlDataReader such as:
Dim myReader As SqlDataReader = myCommand.ExecuteReader
Do While myReader.Read()
'look at columns and set the value to sUserID
sUserID = myReader.Item("Userid")
sUserEmail = myReader.Item("Email")
Loop
myReader.Close()
myReader = Nothing
Return sUserID, sUserEmail
Chris Stewart
www.pluginforsuccess.com
|
|
|
|
|
A method can only have one return value. Make a user class, create an instance of it in the method, populate it with the data and return it.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
|
|
Dude, what world are you living in? Nobody's going to send you the solution by email. So you can stop hoping for that. What I recommend is reading an ASP.NET book, like Professional ASP.NET[^] which has the answer to your problem.
Oh, and to ease the way through, you're not looking for dynamic page creation, but paging.
Cheers,
Mircea
"Pay people peanuts and you get monkeys" - David Ogilvy
|
|
|
|
|
Mircea Grelus wrote: what world are you living in? Nobody's going to send you the solution by email. So you can stop hoping for that.
Exactly.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I am using ajax.net. I am using the update panal. I have already put a script manager control. When run this form then display run time message below this.
"Only one instance of a ScriptManager can be added to the page."
|
|
|
|
|
Mr Gagan just not ask repeated question again and again. Do yourself ok. And try to find out why error is coming. Not like Sonia Gupta to get all the solve code.
Ok ........
Devjit Das.
|
|
|
|
|
Not reapeat same question. My previous error:
"The control with ID 'UpdatePanel1' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it."
Now error: Only one instance of script manager control.
I am using the webuserconrol when webusercontrol under the use ajax.net
I am using the webusercontrol my aspx page under update panel. then create this problem
Only one instance of script manager control.
when webusercontrol put outside the update panel. and not use scriptmanager control. run project and not display error. but project requirment that under updatepanel.
|
|
|
|
|
Have you tried these[^] solutions?
Cheers,
Mircea
"Pay people peanuts and you get monkeys" - David Ogilvy
|
|
|
|
|
if u install ajax.net setup
and u found
Only one instance of a ScriptManager can be added to the page.?????
then u can try to create another website under chose ajaxenablewebsite
in give template
and put hole file and folder in ajax enable directory
no knowledge in .net
|
|
|
|