Preinit Event shows error with Master/Content Page

  • Thread starter Thread starter Rahul
  • Start date Start date
R

Rahul

this is my code in preinit event
I have "hlinkAdd" as hyperlink web control and i am using a master page, and below code is of content page preinit event.

Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
If Request.QueryString("process") = "" Or Request.QueryString("process") = "Add" Then
hlinkAdd.SkinID = "up" (error is thrown here Object reference not set to an instance of an object)
hlinkAdd.NavigateUrl = ""
trCompanyName.Visible = False
ElseIf Request.QueryString("process") = "Edit" Then
'LinkEdit.ForeColor = Drawing.Color.Aqua
hlinkEdit.SkinID = "up"
hlinkEdit.NavigateUrl = ""
cmbCompanyName.AutoPostBack = True
trCompanyName.Visible = True
End If
End Sub

I get the following error ....


Please help me ...

Rahul
 
hyperlink is in the content page

OK - three questions:

1) have you set AutoEventWireup to True?

2) what happens if you set the QueryString value to Edit?

3) does it work if you move the code into Page_Init or Page_Load?
 
OK - three questions:
1) have you set AutoEventWireup to True?
yes .... but both ways it doesn't work
2) what happens if you set the QueryString value to Edit?
not using query string ....
3) does it work if you move the code into Page_Init or Page_Load?
in page load anyways you can't set skin id or use visible property of the control.
pre_init is the place for that ..
let me elaborate on this again....
if there is no master page and if I use the following logic it works find for any page...
only in case of master/content pages it doesn't work..
it says "Object reference not set to an instance of an object"
that means it is not able to initialise thses elments of content page.


Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
If Request.QueryString("process") = "" Or Request.QueryString("process") = "Add" Then
hlinkAdd.SkinID = "up" (error is thrown here Object reference not set to an instance of an object)
hlinkAdd.NavigateUrl = ""
trCompanyName.Visible = False
ElseIf Request.QueryString("process") = "Edit" Then
'LinkEdit.ForeColor = Drawing.Color.Aqua
hlinkEdit.SkinID = "up"
hlinkEdit.NavigateUrl = ""
cmbCompanyName.AutoPostBack = True
trCompanyName.Visible = True
End If
End Sub

Rahul
 
sorry ..... that is still not developed ....
right now working on default condition only ....
for any querystring value the page will be same ....

Rahul
 
Back
Top