Adding eventhandler to control

  • Thread starter Thread starter Neven Klofutar
  • Start date Start date
N

Neven Klofutar

Hi,

How can I add an even handler to a control that is not situated on the main
page (it's situated in the repeater).
How do I rewrite this to make it work ?

Thanx, Neven
 
Neven,

You would have to get the instance of the control in the repeater, and
set the event handler like you would any other control.

Hope this helps.
 
Hi Neven,


You can do it in the aspx file itself, take a look at the line below, this
is declared inside a DataGrid but it should work on any list control,
including the repeater.
If this is of not help , just post the piece of code and the event you are
trying

<asp:imagebutton Visible="True" runat="server" ToolTip="Save Changes"
OnClick="UpdateItem" ImageUrl="images/ico_ok.gif" ID="Imagebutton2" />

See how I declare the OnClick handler.

Cheers,
 
I really don't know how to maki it work, I tried everything ...
I have btnSearch button that works perfectly and it's situated on the mail
page, and I have btnPlanetName that is situated in the header template of
the repeater that I can't make it to work ...
Please help, I'm getting desperate ...

Here's part of my code ...
-------------------
<asp:button id=btnSearch runat="server" ForeColor="White" BorderWidth="1px"
BorderStyle="Solid" BorderColor="Black" BackColor="Maroon" Text="Search
!"></asp:button>

<asp:repeater id=rpScan runat="server" EnableViewState="False">
<HeaderTemplate>
<table border='0' width='100%'>
<tr>
<th>
<asp:Button Runat=server ID=btnPlanetName Text='Planet Name'
BackColor='darkgreen' BorderWidth='0' ForeColor='white' Font-Size='11px'
Font-Bold=True Font-Underline=True style='CURSOR: hand'
OnClick="btnPlanetName_Click"></asp:Button>
</th>
 
Thanx everyone for your help ...
I'm suck an idiot !!!!

I turned off viewstate on the repeater, so ... :(

SORRY !!!!

Neven


Neven Klofutar said:
I really don't know how to maki it work, I tried everything ...
I have btnSearch button that works perfectly and it's situated on the mail
page, and I have btnPlanetName that is situated in the header template of
the repeater that I can't make it to work ...
Please help, I'm getting desperate ...

Here's part of my code ...
-------------------
<asp:button id=btnSearch runat="server" ForeColor="White" BorderWidth="1px"
BorderStyle="Solid" BorderColor="Black" BackColor="Maroon" Text="Search
!"></asp:button>

<asp:repeater id=rpScan runat="server" EnableViewState="False">
<HeaderTemplate>
<table border='0' width='100%'>
<tr>
<th>
<asp:Button Runat=server ID=btnPlanetName Text='Planet Name'
BackColor='darkgreen' BorderWidth='0' ForeColor='white' Font-Size='11px'
Font-Bold=True Font-Underline=True style='CURSOR: hand'
OnClick="btnPlanetName_Click"></asp:Button>
</th>
.
.
.



public class searchOpensNEW : System.Web.UI.Page {

.
.
protected System.Web.UI.WebControls.Button btnPlanetName;


private void InitializeComponent() {
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
}



public void btnPlanetName_Click(object sender, System.EventArgs e) {
lblSortName.Text = "name";

if (lblSortOrder.Text == "DESC") {
lblSortOrder.Text = "ASC";
} else {
lblSortOrder.Text = "DESC";
}
search4Opens("name", lblSortOrder.Text);
}


public void search4Opens(string sortName, string sortOrder) {
string stProc = "GalaxyScanFinder";
SqlParameter[] arrParams =
SqlHelperParameterCache.GetSpParameterSet(UtilityDB.getConnectiongString(),
stProc);
arrParams[0].Value =
UtilityGeneral.toDatumSQLFull(DateTime.Parse(cmbTime1.SelectedItem.Value));
arrParams[1].Value =
UtilityGeneral.toDatumSQLFull(DateTime.Parse(cmbTime2.SelectedItem.Value));
arrParams[2].Value = Int32.Parse(txtLand1.Text);
arrParams[3].Value = Int32.Parse(txtLand2.Text);
arrParams[4].Value = chkOpensOnly.Checked.ToString();
arrParams[5].Value = sortName;
arrParams[6].Value = sortOrder;

SqlDataReader drScan =
SqlHelper.ExecuteReader(UtilityDB.getConnectiongString(),
CommandType.StoredProcedure, stProc, arrParams);

rpScan.DataSource = drScan;
rpScan.DataBind();

UtilityDB.drClose(drScan);
}


private void btnSearch_Click(object sender, System.EventArgs e) {
search4Opens("land2", "desc");
}


}



"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%23FF0AX%[email protected]...
Hi Neven,


You can do it in the aspx file itself, take a look at the line below, this
is declared inside a DataGrid but it should work on any list control,
including the repeater.
If this is of not help , just post the piece of code and the event you are
trying

<asp:imagebutton Visible="True" runat="server" ToolTip="Save Changes"
OnClick="UpdateItem" ImageUrl="images/ico_ok.gif" ID="Imagebutton2" />

See how I declare the OnClick handler.

Cheers,
 
Back
Top