Solved

ImageButton Web Control initialization problem

Posted on 2003-12-03
7
278 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
Comment Utility
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
Comment Utility
However your declaration is just not correct...

It should be

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

Author Comment

by:whoiswho
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:whoiswho
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
override protected void OnInit(EventArgs e)
  base.OnInit(e);
  page_init();
}
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now