Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ImageButton Web Control initialization problem

Posted on 2003-12-03
7
Medium Priority
?
286 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

664 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