Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ImageButton Web Control initialization problem

Posted on 2003-12-03
7
Medium Priority
?
287 Views
Last Modified: 2008-03-03
Hello,

I have a problem with my ImageButton command initialization.  I think if I remember right, the initialization for web controls and the page_init are random?  Anyways, the problem is that my "onCommand" control for the ImageButton uses variables that are initialized by page_init.  How do I set it so that page_init gets run first before my ImageButton does?

Relevant scripts:

(HTML File)
<asp:ImageButton
ID="SomeButton"
onCommand="onCommand_RunButton"

(C# File)
protected void page_init() {
  Run this first.
}

protected void onCommand_RunButton(...) {
  Run this after page_init.
}
0
Comment
Question by:whoiswho
  • 4
  • 3
7 Comments
 
LVL 18

Expert Comment

by:testn
ID: 9871887
It isn't random.....

Page_Init will be called by onCommand_RunButton() .... always..... You don't have to do anything.
0
 
LVL 18

Expert Comment

by:testn
ID: 9871889
However your declaration is just not correct...

It should be

override protected void OnInit(EventArgs e)
  Run this first.
}
0
 

Author Comment

by:whoiswho
ID: 9877772
I need Page_Init to initialize my C# code-behind.  Did you mean I should put a declaration for onInit in my C# file?  If so, how do I tie it in so that it calls on page_init?  That is where my variables are being initialized.  For example:

(C# File)
int i;
protected void page_init() {
  i = 5;
}

protected void onCommand_RunButton(...) {
  if (i == 5)
    i = 9;
}

That is more or less the logic I have it in right now but when I click on the button in the HTML file, it says "Object reference not set to an instance of an object."  If I take out "if (i==5)" it works, but of course, not what I want it to do.  I guess adding "OnInit" would help, but how can I tell onInit to call page_init?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:whoiswho
ID: 9877779
I need Page_Init to initialize my C# code-behind.  Did you mean I should put a declaration for onInit in my C# file?  If so, how do I tie it in so that it calls on page_init?  That is where my variables are being initialized.  For example:

(C# File)
int i;
protected void page_init() {
  i = 5;
}

protected void onCommand_RunButton(...) {
  if (i == 5)
    i = 9;
}

That is more or less the logic I have it in right now but when I click on the button in the HTML file, it says "Object reference not set to an instance of an object."  If I take out "if (i==5)" it works, but of course, not what I want it to do.  I guess adding "OnInit" would help, but how can I tell onInit to call page_init?
0
 

Author Comment

by:whoiswho
ID: 9877787
I need Page_Init to initialize my C# code-behind.  Did you mean I should put a declaration for onInit in my C# file?  If so, how do I tie it in so that it calls on page_init?  That is where my variables are being initialized.  For example:

(C# File)
int i;
protected void page_init() {
  i = 5;
}

protected void onCommand_RunButton(...) {
  if (i == 5)
    i = 9;
}

That is more or less the logic I have it in right now but when I click on the button in the HTML file, it says "Object reference not set to an instance of an object."  If I take out "if (i==5)" it works, but of course, not what I want it to do.  I guess adding "OnInit" would help, but how can I tell onInit to call page_init?
0
 

Author Comment

by:whoiswho
ID: 9877788
I need Page_Init to initialize my C# code-behind.  Did you mean I should put a declaration for onInit in my C# file?  If so, how do I tie it in so that it calls on page_init?  That is where my variables are being initialized.  For example:

(C# File)
int i;
protected void page_init() {
  i = 5;
}

protected void onCommand_RunButton(...) {
  if (i == 5)
    i = 9;
}

That is more or less the logic I have it in right now but when I click on the button in the HTML file, it says "Object reference not set to an instance of an object."  If I take out "if (i==5)" it works, but of course, not what I want it to do.  I guess adding "OnInit" would help, but how can I tell onInit to call page_init?
0
 
LVL 18

Accepted Solution

by:
testn earned 600 total points
ID: 9882378
override protected void OnInit(EventArgs e)
  base.OnInit(e);
  page_init();
}
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question