I have master page in which I am using modalpopupextender under which there are login form. Now In my client(aspx) page I want to use same Login form from that modalpopupextender. So I tried to get it's control from master page but it's giving me error.
Object reference not set as an instance of an object.
Client Page (Code Behind)
Private Sub orderButton_Click(sender As Object, e As EventArgs) Handles orderButton.Click
Dim mploginM As AjaxControlToolkit.ModalPopupExtender = DirectCast(Page.Master.FindControl("mp0"), AjaxControlToolkit.ModalPopupExtender)
If HttpContext.Current.Request.Cookies("chkusername") Is Nothing Then
mploginM.Show()
End If
End Sub
But after clicking (when cookies chkusername is empty) it's not showing login form popup. I checked ModalPopupExtender ID in my master page & it's corrrect. Is that anything I am doing wrong here?
There seem to be naming issue when a page with master page. In short, you need to call FindControl
twice - one time for a master page and then for a content page.
Please see this thread for code sample: Find a control on a page with a master page