Solved

ImageButton Web Control initialization problem

Posted on 2003-12-03
7
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 200 total points
ID: 9882378
override protected void OnInit(EventArgs e)
  base.OnInit(e);
  page_init();
}
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

630 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