Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 9-Nov-17 23:27pm

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-
JavaScript
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 :)
 
Share this answer
 
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) %>' />
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.
 
Share this answer
 
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.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900