Category Archives: AJAX

[RESOLVED] FindControl method doesn't work with masterpage

Hi all, i have a masterpage and other pages. i want to use findcontrol method to find a textbox (not on the master page) to check whether it is empty or not.

my code is as folows;

Dim myContentPlaceHolder As ContentPlaceHolder = CType(Master.FindControl("MainContent"), ContentPlaceHolder)

Dim UpdatePanel1 As UpdatePanel = CType(myContentPlaceHolder.FindControl("UP1"), UpdatePanel)

Any help please. 


Dim tmptxt As TextBox = CType(Master.FindControl("txtbox1"), TextBox)

If Not tmptxt Is Nothing Then
 'get tmptxt.Text value
End If

my textbox in not on the masterpage, it is on the default.aspx page. i tried

Dim myTextBox As TextBox = CType(Master.FindControl("TextBox1"), TextBox)  , but doesn't worked. Any more help please

i should also mention that the TextBox1 is inside listview, the listview is inside an updatepanel (updatepanel is inside a panel -ajax modalpopupextender).


First you need to find the textbox in listview. Since I'm not sure which textbox you find in listview. Here's a example:

<asp:ListView ID="ListView1" runat="server">
                <tr id="Tr2" runat="server">
                    <td align="center">
                        <asp:Label ID="lbP1" runat="Server" Text='<%#Eval("P1") %>' />
                    <td align="center">
                        <asp:Label ID="lbP2" runat="Server" Text='<%#Eval("P2") %>' />

Protected Sub FindItems()
	Dim ctl As Control = Me.ListView1.Items(0).FindControl("lbP1")  //find textbox in the first item of ListView
End Sub

Protected Sub Button1_Click(sender As Object, e As EventArgs)
End Sub

Find the child page's ListView in masterpage:

Dim panel As UpdatePanel = TryCast(Me.ContentPlaceHolder1.FindControl("UpdatePanelID"), UpdatePanel)
Dim listview As ListView = TryCast(panel.FindControl("ListViewID"), ListView)

Please notice that if the control is wrapped in a parent control, you need to first find the control from this parent control(container).

Here are some good article:

Hope this can help you.

[RESOLVED] creating hyperlinks dynamically.

I want to create hyperlink dynamically whenever i click the button below is my code

int j = 1;
        for (int i = 0; i < j; j++)
            //HyperLink links = new HyperLink();
            HyperLink hplink = new HyperLink();
            hplink.NavigateUrl = "";
            hplink.Text = "Click Here" + "<br /><br />";

but i am unable to get the hyperlinks dynamically because the loop is going infinite.

for (int i = 0; i < j; j++) 

--> for (int i = 0; i < j; i++) 

Replace j++ with i++, since i is your looping variable. 

Ya when i have done what you have said but i am getting only one hyperlink when i press the button,i want to createhyperlinks whenever i click the button, i mean how many times i click the button that many times i have to get hyperlink. 

Here is a way to do that

1;) in your aspx markup :

    <form id="form1" runat="server">
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    <br />
    <asp:Literal runat="server" ID="LinksPlaceHolder" />

2;) in the code-behind :

    protected void Button1_Click(object sender, EventArgs e)
            LinksPlaceHolder.Text += "<a href=\"\">go to the website</a><br/></br>";

if this  is not what you want, explain exactly what your are trying to do

This video shows one way of doing something like that: 

There is a major problem with creating a new hyperlink each time a button is pressed.  Dynamic controls have to be redrawn each time the page loads.  In order to redraw a different hyperlink each time a button is pressed you will need to have a lists of hyperlinks in a DataTable or HybridDictionary that create the hyperlinks each time the button click causes a postback.  Your redraw loop is close but it should use a For Each and loop through the collection of hyperlink data and draw a control for each one during the Page Init method.  In the button click simply add the new hyperlink data to the collection.  Dynamic controls are pain and should be avoided whenever possible. 

Are you saying about tables rows and columns and adding the control to column and generating whenever the button is clicked?? but i want to achieve with a for loop is it possible?? 

For example the DataTable would contain columns CONTROL_ID, URL, TEXT.  Each time the button is clicked you create a new row from the DataTable fill in the fields and add the row to the data and store it in the ViewState.  Each time the page load you read the DataTable with your for each Row loop and add your hyperlinks to the placeholder.  This will make sure the drawing is constant each time and you only have to debug the data is getting updated and added properly.   

I think a little bit of code can explain much than big sentences.

Invalid loop for (int i = 0; i < j; j++)  

Write loop 

>> for (int i = 0; i < j; i++)  


Http is stateless, Dynamically created control can not maintain itself after postback.

If you dynamically add a HyperLink Control to the page during button click, be aware that every PostBack is a new Request .They need to be recreated each time the page loads.

Check this two links, they give you some example and explanation:

Hope this can help you.

Here you have increamented j++, that should be i++. so in your case conditon not get false at any time so that is goes in infinate looks

change as per below code

int j = 1;
        for (int i = 0; i < j; i++)
            //HyperLink links = new HyperLink();
            HyperLink hplink = new HyperLink();
            hplink.NavigateUrl = "";
            hplink.Text = "Click Here" + "<br /><br />";


Please mark as answer if this is helps


[RESOLVED] With IE 9, where does VS store the temporary files when viewing in the browzer

My computer had an issue while I was in the middle of debugging my web app.  When this happens, I get an error message stating:

Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies"

In the past, all that I had to do was to go into the folder windows/microsoft.NET/Framework64/v4.0.30319

and delete the temporaryinternet files.

After updating to IE 9, I went into the folder and they aren't there anymore.

Where does IE 9 put them?



Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies"

It seems you've not referenced AjaxToolkit in your application. Check out your bin folder or make sure you've referenced mentioned dll in your apps.

I know that would be the general thought, but it isn't in this case since it is referenced.  I know it has to do with aborting in the middle of view the session, and leaving temporary files.  I have had it happen a thousand times. 

I removed IE 9, went back to IE 8, and am up and running.  It happened again using IE 8. and I went in and deleted the temporary folder as I suggested above and it was running again.

I boosted my voltage on my ram and am not having any lock-ups, so hopefullly it won't be an issue for me anyway.

Thanks for your reply.

[RESOLVED] Clear Text in Ajax ComboBox or DropDownList

When the WebPage loads i would like for the Text to be cleared in Ajax ComboBox and/or DropDownList. However Setting the text to nothing or null doesn't seem to work. So I did some searching and found this...

Private Sub SampleLoad()

  For i as integer = 1 to 10
    ComboBox1.Items.Add("Item" & i)

  'Add a null item to clear the text
  ComboBox1.Items.Insert(0, "")
  ComboBox1.SelectedIndex = 0

End Sub

Is there another way to clear the text other then adding a null item to the list? I don't really want the user to have a selection of "null", this seems like a hack job.


Just a thought, does it need to be visible? Can you simply hide it?

comboBox1.SelectValue = ""

In your load event?


 How about converting to an Ajax Object in code after page loads.


And, if you try like this?


For i = o To i <= 10 Then
ComboBox1.Items.Add("item" + i);

It worked?

Just so I understand, you just want nothing selected by default? If that is the case, for a dropdownlist, you will need a blank row.  I usualy just add one with text of "SELECT NAME" or whatever, then validate later that something has been selected. For a listbox, you can set the selectedindex to -1 (again, you will still need to validate selection later.


i don't think there is any other way except adding a null or some default text like "select here" and later you have to validate it to see if user changed the default value or not.  



i don't think there is any other way except adding a null or some default text like "select here" and later you have to validate it to see if user changed the default value or not.  


Thats what I thought. I spent a couple hours googling an answer to this problem and came up with the original post. I just don't want them to be able to select "" from the items list. But I guess it is what it is and just use some validation.

I guess a person could write there own user control to this maybe using TextBox and DropDownExtender and JavaScript. Seems like to much work for something so simple though.

that happens when you try to do something that is not suppose to be done with a certain control.

if you don't want anything to be selected then you should change your design and use ListBox instead of ddl while if you want something to be always selected by default then ddl would be your primary choice.  

set the combobox's selectedIndex to the -1 and it will be select nothing at all 

[RESOLVED] Loading please wait in VB.NET while gridview loads data


I am trying to display the loading please message or a spinning image while a page loads data in a gridview. Users click on a link from one page and get redirected to another page via the response.redirect method. The new page loads some data in a gridview based upon some variables passed. Some times it could take up to 20+ seconds for the gridview to load. I have displayed loading please wait message previously using the jQuery, Post and ajax methods etc. In this case it's just straight VB.NET code that makes a sql connection to the server, executes a stored procedure and binds the returned data to the gridview. I would like the message or image to start showing once they click on the link to get redirected to the new page and continue to display till the gridview data has been loaded. Here is an example of the code:

Dim cmd As SqlCommand = New SqlCommand("CustOrderHist", New SqlConnection("Server=localhost;Database=Northwind;Trusted_Connection=True;"))
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.AddWithValue("CustomerID", txtCustID.Text)
gvwExample.DataSource = cmd.ExecuteReader()
Catch ex As Exception
lblStatus.Text = ex.Message
End Try


To avoid the loading time. What you can do is lazy load the gridview after the page is loaded using Updatepanel and Timer

This way your page will be loaded while the gridview will be populated later. 

Thank you, this trick seemed to work great for me.