Thursday, March 29, 2012

Pass Parameter to Javascript

I have javascript that accepts 2 parameters like so...
function showmsgbox(chkB, somestring)
{
xState=chkB.checked;
if(xState)
{
chkB.parentElement.parentElement.style.backgroundColor='yellow';
}
else
{
chkB.parentElement.parentElement.style.backgroundColor='whitesmoke';
}
alert(somestring);
}
I need to pass the second parameter o the function from within a datagrid
like so... Only problem is I keep getting many erros with my syntax. How
can this be accomplished?...
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="chkBox1" onclick="javascript:HighlightRow(this, '<%#
DataBinder.Eval(Container, "DataItem.column1") %>'');" runat="server"
autopostback="False"/>
</ItemTemplate>
</asp:TemplateColumn>
Thanks.I did it through the (gridview's) row event.
Using findcontrol and adding the onclick there.
However, a few days ago this kind of syntax was posted, i haven't tried it
yet.
<asp:ImageButton id="x" OnClientClick=<%# "menu('" + Eval("TableId") +
"');return false;"%> />
Maybe it helps?
"Jay" <msnews.microsoft.com> schreef in bericht
news:OpCSvNG9FHA.1416@.TK2MSFTNGP09.phx.gbl...
>I have javascript that accepts 2 parameters like so...
> function showmsgbox(chkB, somestring)
> {
> xState=chkB.checked;
> if(xState)
> {
> chkB.parentElement.parentElement.style.backgroundColor='yellow';
> }
> else
> {
> chkB.parentElement.parentElement.style.backgroundColor='whitesmoke';
> }
> alert(somestring);
> }
> I need to pass the second parameter o the function from within a datagrid
> like so... Only problem is I keep getting many erros with my syntax. How
> can this be accomplished?...
> <asp:TemplateColumn>
> <ItemTemplate>
> <asp:CheckBox ID="chkBox1" onclick="java script:HighlightRow(this, '<%#
> DataBinder.Eval(Container, "DataItem.column1") %>'');" runat="server"
> autopostback="False"/>
> </ItemTemplate>
> </asp:TemplateColumn>
> Thanks.
>
Here is the failing code regarding that post:
<asp:ImageButton ID="ImageButton2" runat="server"
It seems menu is a function.
"Edwin Knoppert" <info@.pbsoft.speedlinq.nl> schreef in bericht
news:dmftqs$f14$1@.azure.qinip.net...
>I did it through the (gridview's) row event.
> Using findcontrol and adding the onclick there.
> However, a few days ago this kind of syntax was posted, i haven't tried it
> yet.
> <asp:ImageButton id="x" OnClientClick=<%# "menu('" + Eval("TableId") +
> "');return false;"%> />
> Maybe it helps?
>
> "Jay" <msnews.microsoft.com> schreef in bericht
> news:OpCSvNG9FHA.1416@.TK2MSFTNGP09.phx.gbl...
>
the onclick is the serverside click. in the codebehind, you to add the
client onclick in the code behind using
checkbox.Attributes["onclick"] = value;
to add at the individual level, use the ItemDataBound Event of the repeater.
-- bruce (sqlwork.com)
"Jay" <msnews.microsoft.com> wrote in message
news:OpCSvNG9FHA.1416@.TK2MSFTNGP09.phx.gbl...
>I have javascript that accepts 2 parameters like so...
> function showmsgbox(chkB, somestring)
> {
> xState=chkB.checked;
> if(xState)
> {
> chkB.parentElement.parentElement.style.backgroundColor='yellow';
> }
> else
> {
> chkB.parentElement.parentElement.style.backgroundColor='whitesmoke';
> }
> alert(somestring);
> }
> I need to pass the second parameter o the function from within a datagrid
> like so... Only problem is I keep getting many erros with my syntax. How
> can this be accomplished?...
> <asp:TemplateColumn>
> <ItemTemplate>
> <asp:CheckBox ID="chkBox1" onclick="java script:HighlightRow(this, '<%#
> DataBinder.Eval(Container, "DataItem.column1") %>'');" runat="server"
> autopostback="False"/>
> </ItemTemplate>
> </asp:TemplateColumn>
> Thanks.
>

0 comments:

Post a Comment