Preinit Event shows error with Master/Content Page

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
 
M

Mark Rae

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?
 
R

Rahul

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
 
M

Mark Rae

not using query string ....

So why are you checking for one:

If Request.QueryString("process") = "" Or Request.QueryString("process") =
"Add" Then

???
 
R

Rahul

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

Rahul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top