Click here to Skip to main content
13,801,728 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi All,
I already know how it works with a single parameter.Is it possible with two parameters.

What I have tried:

OnClientClick='<%# Eval("psid", "window.open(\"add.aspx?cid={0}\", null,\"scrollbars=yes,top=10,left=10\", \"true\");") %>'


One parameter is a textbox value.Thanks in advance
Posted 9-Nov-17 23:54pm
Updated 10-Nov-17 0:27am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

From your code it looks you are not exactly passing values to any function, so I afraid that's not possible, although I am not a PRO in Javascript.
However, you can always pass as many parameters required to a function using Eval.

In that case, your code should look something like following-
OnClientClick='<%# "MyFunctionName(" +Eval("FirstParameter") + ","+Eval("SecondParameter")+" );" %>'


It looks like you want to open a new window as well, which you can write inside the function as well.

Please let me know if something is not clear or if you need further help.

Thanks :)
  Permalink  
Comments
Member 12926744 10-Nov-17 5:30am
   
Thanks for your reply.Can we pass a textbox value as parameter.If so ,could you please tell me how.Since I couldn't find an appropriate way though.
Suvendu Shekhar Giri 10-Nov-17 5:34am
   
You need find that using document.getElementById().
Let me know if further help needed.
Member 12926744 10-Nov-17 6:13am
   
Thank you very much.Got the answer
<asp:Button runat="server" ID="btn" OnClientClick='<%# string.Format("window.open(\"add.aspx?cid={0}¶m2=\" + document.getElementById(\"{1}\").value, null,\"scrollbars=yes,top=10,left=10\", \"true\");", Eval("psid"), Form.FindControl("txt_chqdate").ClientID) %>' />
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Pass two params like

add.aspx?param1=123&param2=456


However if the second parameter needs to be the value of a textbox you're probably better not using OnClientClick but pure javascript on the page. You'll need something like

<asp:TextBox ID="TextBox1" runat="server" />
<asp:Button runat="server" ID="btn" OnClientClick='<%# string.Format("window.open(\"add.aspx?cid={0}&param2=\" + document.getElementById(\"{1}\").value, null,\"scrollbars=yes,top=10,left=10\", \"true\");", Eval("psid"), Container.FindControl("TextBox1").ClientID) %>' Text="click"/>


How you find the textbox to get its id depends where the textbox is though and what kind of textbox it is, neither of which you've said.
  Permalink  
v3
Comments
Suvendu Shekhar Giri 10-Nov-17 5:33am
   
5ed! Makes sense.
Member 12926744 10-Nov-17 5:37am
   
<asp:TextBox ID="txt_chq" CssClass="txtch" Width="250px" runat="server">
This is my textbox field to be passed.
However I am getting an error 'does not contain a definition for FindControl " in the above code.Could you please help me.
F-ES Sitecore 10-Nov-17 5:43am
   
You haven't given the code enough context, the solution depends on what element the OnClientClick attribute is on and if that is databound etc, none of which you have explained.
Member 12926744 10-Nov-17 5:47am
   
OnClientClick attribute is on an imagebutton.
<asp:templatefield>
<itemtemplate>
<asp:ImageButton ID="ibut_Print" runat="server" target="_blank" OnClientClick='<%# Eval("psid", "window.open(\"add.aspx?cid={0}\", null,\"scrollbars=yes,top=10,left=10\", \"true\");") %>'
AlternateText="View" CssClass="btn5" ForeColor="White" ToolTip="Print Invoice" />

<ItemStyle HorizontalAlign="Center" Width="15px" />
F-ES Sitecore 10-Nov-17 6:06am
   
You still haven't explained where the textbox is. People can't give solutions to things without the right details. Where controls sit and how they are bound makes all the difference and without the relevant info it's impossible to give accurate answers.
Member 12926744 10-Nov-17 6:11am
   
Well got the answer.

<asp:Button runat="server" ID="btn" OnClientClick='<%# string.Format("window.open(\"add.aspx?cid={0}¶m2=\" + document.getElementById(\"{1}\").value, null,\"scrollbars=yes,top=10,left=10\", \"true\");", Eval("psid"), Form.FindControl("txt_chqdate").ClientID) %>' />

Thank you very much for your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.181215.1 | Last Updated 10 Nov 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100