pamela rizk
asked on
javascript functions
dear all ,
i have a web user control that contains a combobox in asp web application.
inside this web user control i have a javascript function that return what is the value selected from the combo
on the other hand i have created a web page where i dragged inside 3 web user controls.
i realize that once page go the browser one html file will be created where javascript function exist 3 times for each control.
how can i have a javascript function in the user control with a certain id ion order to avoid this problem.
thank you in advance
i have a web user control that contains a combobox in asp web application.
inside this web user control i have a javascript function that return what is the value selected from the combo
on the other hand i have created a web page where i dragged inside 3 web user controls.
i realize that once page go the browser one html file will be created where javascript function exist 3 times for each control.
how can i have a javascript function in the user control with a certain id ion order to avoid this problem.
thank you in advance
check this, you can include this multiple times without any issues
<select ID="cbo_currenciesofamount1" runat="server" CssClass="DropDownCurveStyle" Width="100%" onfocus="Change_cbo(this, event)" onblur="Change_cbo(this, event)" onchange="cbo_currenciesofamount_IndexChange(this, event);">
<option>11</option>
<option>12</option>
<option>13</option>
</select>
<select ID="cbo_currenciesofamount2" runat="server" CssClass="DropDownCurveStyle" Width="100%" onfocus="Change_cbo(this, event)" onblur="Change_cbo(this, event)" onchange="cbo_currenciesofamount_IndexChange(this, event);">
<option>21</option>
<option>22</option>
<option>23</option>
</select>
<select ID="cbo_currenciesofamount3" runat="server" CssClass="DropDownCurveStyle" Width="100%" onfocus="Change_cbo(this, event)" onblur="Change_cbo(this, event)" onchange="cbo_currenciesofamount_IndexChange(this, event);">
<option>31</option>
<option>32</option>
<option>33</option>
</select>
function Change_cbo(cb, event) {
var cbv = parseInt(cb.options[cb.selectedIndex].value);
//alert(cbv);
console.log("Change_cbo - " + cb.selectedIndex + " > " + cbv);
}
function cbo_currenciesofamount_IndexChange(cb, event) {
var cbv = parseInt(cb.options[cb.selectedIndex].value);
//alert(cbv);
console.log("cbo_currenciesofamount_IndexChange - " + cb.selectedIndex + " > " + cbv);
}
https://jsfiddle.net/HainKurt/7vade2s3/
and put that js into say myuc.js
use this code on page_load of uc
this way, it will be registered once...
although adding it multiple times (the version I posted) will not create any issues...
use this code on page_load of uc
' Define the name, type and url of the client script on the page.
Dim csname As String = "myuc"
Dim csurl As String = "~/myuc.js"
Dim cstype As Type = Me.GetType()
' Get a ClientScriptManager reference from the Page class.
Dim cs As ClientScriptManager = Page.ClientScript
' Check to see if the include script is already registered.
If (Not cs.IsClientScriptIncludeRegistered(cstype, csname)) Then
cs.RegisterClientScriptInclude(cstype, csname, ResolveClientUrl(csurl))
End If
this way, it will be registered once...
although adding it multiple times (the version I posted) will not create any issues...
and dont use anything like
<%=myControl.ClientId%>
in your js file, they will not work!
<%=myControl.ClientId%>
in your js file, they will not work!
Write a function in such a way that it accepts controlId instead of hardCoding in the function itself.
ASKER
to mr hainkurt
i dont need to add 3 cbo in my web form i need a solution for adding 3 user control in a web form
is teher any solution to get control id in javascript common file?
i dont need to add 3 cbo in my web form i need a solution for adding 3 user control in a web form
is teher any solution to get control id in javascript common file?
ASKER
to mr magur,
how to do that?
how to do that?
i dont need to add 3 cbo in my web form i need a solution for adding 3 user control in a web form
is teher any solution to get control id in javascript common file?
I posted the solution...
1. create a js file
2. put those modified functions inside
3. register it (it will be added once)
whats the problem here?
Demo is to show how the end result will be...
I suspect the solution here is quite easy however I must admit I am not clear on the requirements.
If you could show us with actual data examples so we can see what the required result will be it will help to clarify the issue.
If you could show us with actual data examples so we can see what the required result will be it will help to clarify the issue.
check my posts again
ID: 42333646
ID: 42333650
you need:
1. modify your js functions as above
2. create a js file and put code inside and place somewhere in your web site
3. use the registration code on page_load of your user control...
ID: 42333646
ID: 42333650
you need:
1. modify your js functions as above
2. create a js file and put code inside and place somewhere in your web site
3. use the registration code on page_load of your user control...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it worked perfectly
ASKER
Open in new window
and cbo_currenciesofamount_Ind
Open in new window