Solved

ImageButton Web Control initialization problem

Posted on 2003-12-03
7
281 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

821 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