Categories
askquestion

How to pass Page as ref parameter to a function

How to pass Page as ref parameter to a function

Ask Question

Asked
11 years ago

Active
11 years ago

Viewed
4k times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

2

1

I would like to know how Can I paas Page as Ref Parameter to a function

This is what I want to do

public partial class HomePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!SetupUserPermission.isSessionExpired())
{
string UserId = Session[“UserId”].ToString();
SetupUserPermission.SetupUserRights(ref this.Page, Convert.ToInt32(UserId));
}

}
}

c# asp.net

share|improve this question

asked Jan 20 ’09 at 10:27

SandhurstSandhurst

add a comment
 | 

3 Answers
3

active

oldest

votes

4

You can’t pass a property by reference in C#. Why do you want to pass Page by reference in this case?

In VB you can pass a property by reference, and the equivalent in this case would be:

Page tmp = Page;
SetupUserPermission.SetupUserRights(ref tmp, Convert.ToInt32(UserId));
Page = tmp;

Are you really sure you want to do that?

I suspect you don’t really want to pass it by reference, and you’re just slightly confused about parameter passing. See my article on the topic for more information.

share|improve this answer

answered Jan 20 ’09 at 10:33

Jon SkeetJon Skeet

1163k741741 gold badges83578357 silver badges86978697 bronze badges

d’oh! just as I add the same link in ;-p

– Marc Gravell♦
Jan 20 ’09 at 10:35

I’m not going to object to two links to the same article 🙂

– Jon Skeet
Jan 20 ’09 at 11:19

add a comment
 | 

3

Why do you want to pass it ref? It seems to me that a regular pass should do; this passes the reference by value – which is what you want (unless you are creating a new page…).

Also, isn’t “this” the Page? Can’t you just:

SetupUserPermission.SetupUserRights(this, …);

where SetupUserRights takes a Page?

See also: Jon Skeet’s page on parameter passing in C#; that might fix a few misconceptions (hint: Page is a reference-type (a class)).

share|improve this answer

answered Jan 20 ’09 at 10:29

Marc Gravell♦Marc Gravell

848k220220 gold badges22842284 silver badges26622662 bronze badges

add a comment
 | 

0

Unless you need to alter the reference of this.Page in downstream calls and have the reference reflect the changes upstream, there is no reason to pass this by ref. Either way i don’t think this works with properties, especially get only ones like this.Page.

share|improve this answer

answered Jan 20 ’09 at 20:34

Brian RudolphBrian Rudolph

5,44411 gold badge2020 silver badges1717 bronze badges

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Submit

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Blog

Ben Popper is the worst coder in the world: Something awry with my array

This week, #StackOverflowKnows fast planes, math with dates, and code comments

Featured on Meta

TLS 1.0 and TLS 1.1 removal for Stack Exchange services

Did Stack Exchange cut the number of negative comments nearly in half between…

An account of my meeting with the Stack Overflow management team

Related

3087How to cast int to enum?3682How to enumerate an enum0An invalid character was found in the mail header: ‘;’0assigning an id to a programmed textbox in asp.net1access javascript variable in asp.net codebehind0how to store into a session and display current users information0How to Calculate using text box and two gridview items?

Hot Network Questions

How do I show students the Beauty of Mathematics?

Franci de Castellvi – Narcis Vinyoles 18. … Qg6??, a blunder by black?

Is going to Ceres “as easy as going to Mars” like this aerospace engineer says?

Was it possible to listen to music and work on old PCs? When was it possible to for the first time?

If sound passes through material, vibration is produced. So are electromagnetic waves produced too?

Implicit conversion not allowed on return

What does “Manistan” mean?

How to disconnect air conditioner lines from outdoor unit?

Why is the asteroid belt shaped like a triangle?

Help! Ransomware encrypted my files. What do I do now?

create empty img with dd so that it its sectors are of 4096bytes rather than 512

Light task-processing systems with zero dependency for Linux systems

When are consonants pronounced at the end of a word?

How does the file command distinguish text and LaTeX files?

Did Voldemort know that his Muggle father was actually a victim?

Does coiling and straightening a wire change its resistance?

Resigning a couple of months before an event : is it abusive resignation?

How did Atari lose money on home computers?

Why don’t organs have weighted keys?

Providing the spymaster with cues for clues in Codenames

Rescinding offers of admissions

Is the conflict between Captain America and Tony Stark in “The Avengers” Blue Collar versus Educated Elite?

Why can’t Ditto copy eyes properly?

Answer templating

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-cs

Leave a Reply

Your email address will not be published. Required fields are marked *