anyone?? :o( buttons and arguments

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi there, I am using c#, not quite sure how to get an argument into an event.

protected void btnRedirect_Click (object sender, eventargs e) {

go to url newpage?id=[id i passed]

}


i know sender is whatever control invoked this code (e.g. button) but not
sure what the eventargs is for. I have a button which performs a click event.
But I want to send a value to the click event (an id to be passed in an url
redirection). How do I put this string into the argument list of the click
event?

I am also trying to put the id into the click in the html and this is
returning an error (asp server control not formed). The value I want to pass
comes from an asprepeater. what am i missing in the following?

<asp:ImageButton id="btnNext" ImageURL="~/images/but_next.gif" height="17px"
width="48px" onclick="btnViewClient_Click(<%#
DataBinder.Eval(Container.DataItem, "ClientID") %>)" runat="server"/>

Thank you.
 
Try doing:

<asp:ImageButton id="btnNext" CommandArgument='<%#
DataBinder.Eval(Container.DataItem, "ClientID") %>' .... />

then in your code.

string clientId = ((ImageButton)sender).CommandArgument;
Response.Redirect("newPage.aspx?id=" + clientId, true);

Karl
 
it the CommandName and CommandArgument properties.

-- bruce (sqlwork.com)



message | hi there, I am using c#, not quite sure how to get an argument into an
event.
|
| protected void btnRedirect_Click (object sender, eventargs e) {
|
| go to url newpage?id=[id i passed]
|
| }
|
|
| i know sender is whatever control invoked this code (e.g. button) but not
| sure what the eventargs is for. I have a button which performs a click
event.
| But I want to send a value to the click event (an id to be passed in an
url
| redirection). How do I put this string into the argument list of the click
| event?
|
| I am also trying to put the id into the click in the html and this is
| returning an error (asp server control not formed). The value I want to
pass
| comes from an asprepeater. what am i missing in the following?
|
| <asp:ImageButton id="btnNext" ImageURL="~/images/but_next.gif"
height="17px"
| width="48px" onclick="btnViewClient_Click(<%#
| DataBinder.Eval(Container.DataItem, "ClientID") %>)" runat="server"/>
|
| Thank you.
|
 
The Event is raised by the object which raised it. As you didn't define the
class, you have no control over what arguments are passed by it. Therefore,
the solution to passing an argument into an Event is to create an object
that does that. For example, you could create a custom Server Control that
inherits Button, and does its' events differently.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
 
Hi Louise:

You cannot change the signature of the method and the parameters it
requires, but once the event fires you can use information it provides
to dig the information out of the repeater. The sender will be the
button firing the event, and the button's Parent property represents
the row (RepeaterItem) where the button lives.

protected void btnRedirect_Click(object sender, System.EventArgs e)
{
ImageButton btn = sender as ImageButton;
RepeaterItem item = btn.Parent as RepeaterItem;

// pull info from item, ie item.Cells[0]...
}
 
lots of think about. thank you all.

Scott Allen said:
Hi Louise:

You cannot change the signature of the method and the parameters it
requires, but once the event fires you can use information it provides
to dig the information out of the repeater. The sender will be the
button firing the event, and the button's Parent property represents
the row (RepeaterItem) where the button lives.

protected void btnRedirect_Click(object sender, System.EventArgs e)
{
ImageButton btn = sender as ImageButton;
RepeaterItem item = btn.Parent as RepeaterItem;

// pull info from item, ie item.Cells[0]...
}


--
Scott
http://www.OdeToCode.com/blogs/scott/

hi there, I am using c#, not quite sure how to get an argument into an event.

protected void btnRedirect_Click (object sender, eventargs e) {

go to url newpage?id=[id i passed]

}


i know sender is whatever control invoked this code (e.g. button) but not
sure what the eventargs is for. I have a button which performs a click event.
But I want to send a value to the click event (an id to be passed in an url
redirection). How do I put this string into the argument list of the click
event?

I am also trying to put the id into the click in the html and this is
returning an error (asp server control not formed). The value I want to pass
comes from an asprepeater. what am i missing in the following?

<asp:ImageButton id="btnNext" ImageURL="~/images/but_next.gif" height="17px"
width="48px" onclick="btnViewClient_Click(<%#
DataBinder.Eval(Container.DataItem, "ClientID") %>)" runat="server"/>

Thank you.
 
karl it worked, thanks so much

Karl Seguin said:
Try doing:

<asp:ImageButton id="btnNext" CommandArgument='<%#
DataBinder.Eval(Container.DataItem, "ClientID") %>' .... />

then in your code.

string clientId = ((ImageButton)sender).CommandArgument;
Response.Redirect("newPage.aspx?id=" + clientId, true);

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


louise raisbeck said:
hi there, I am using c#, not quite sure how to get an argument into an event.

protected void btnRedirect_Click (object sender, eventargs e) {

go to url newpage?id=[id i passed]

}


i know sender is whatever control invoked this code (e.g. button) but not
sure what the eventargs is for. I have a button which performs a click event.
But I want to send a value to the click event (an id to be passed in an url
redirection). How do I put this string into the argument list of the click
event?

I am also trying to put the id into the click in the html and this is
returning an error (asp server control not formed). The value I want to pass
comes from an asprepeater. what am i missing in the following?

<asp:ImageButton id="btnNext" ImageURL="~/images/but_next.gif" height="17px"
width="48px" onclick="btnViewClient_Click(<%#
DataBinder.Eval(Container.DataItem, "ClientID") %>)" runat="server"/>

Thank you.
 
ok i'm stupid, you gave me single quotes and i used double

louise raisbeck said:
karl it worked, thanks so much

Karl Seguin said:
Try doing:

<asp:ImageButton id="btnNext" CommandArgument='<%#
DataBinder.Eval(Container.DataItem, "ClientID") %>' .... />

then in your code.

string clientId = ((ImageButton)sender).CommandArgument;
Response.Redirect("newPage.aspx?id=" + clientId, true);

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


louise raisbeck said:
hi there, I am using c#, not quite sure how to get an argument into an event.

protected void btnRedirect_Click (object sender, eventargs e) {

go to url newpage?id=[id i passed]

}


i know sender is whatever control invoked this code (e.g. button) but not
sure what the eventargs is for. I have a button which performs a click event.
But I want to send a value to the click event (an id to be passed in an url
redirection). How do I put this string into the argument list of the click
event?

I am also trying to put the id into the click in the html and this is
returning an error (asp server control not formed). The value I want to pass
comes from an asprepeater. what am i missing in the following?

<asp:ImageButton id="btnNext" ImageURL="~/images/but_next.gif" height="17px"
width="48px" onclick="btnViewClient_Click(<%#
DataBinder.Eval(Container.DataItem, "ClientID") %>)" runat="server"/>

Thank you.
 
darn it. I still get 'server control is not well formed' on this.. it worked
when I sent commandargument="3" just to test, but fails when i try to include
the repeater value. any ideas?

<td style="border-bottom: #666666 1px solid" align="right"><asp:ImageButton
id="btnNext" CommandArgument="<%# DataBinder.Eval(Container.DataItem,
"ClientID") %>" onclick="btnViewClient_Click"
ImageURL="~/images/but_next.gif" height="17px" width="48px"
runat="server"/></td>
Line 364: </tr>
Line 365: </ItemTemplate>


Karl Seguin said:
Try doing:

<asp:ImageButton id="btnNext" CommandArgument='<%#
DataBinder.Eval(Container.DataItem, "ClientID") %>' .... />

then in your code.

string clientId = ((ImageButton)sender).CommandArgument;
Response.Redirect("newPage.aspx?id=" + clientId, true);

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


louise raisbeck said:
hi there, I am using c#, not quite sure how to get an argument into an event.

protected void btnRedirect_Click (object sender, eventargs e) {

go to url newpage?id=[id i passed]

}


i know sender is whatever control invoked this code (e.g. button) but not
sure what the eventargs is for. I have a button which performs a click event.
But I want to send a value to the click event (an id to be passed in an url
redirection). How do I put this string into the argument list of the click
event?

I am also trying to put the id into the click in the html and this is
returning an error (asp server control not formed). The value I want to pass
comes from an asprepeater. what am i missing in the following?

<asp:ImageButton id="btnNext" ImageURL="~/images/but_next.gif" height="17px"
width="48px" onclick="btnViewClient_Click(<%#
DataBinder.Eval(Container.DataItem, "ClientID") %>)" runat="server"/>

Thank you.
 
Back
Top