how to change aspx with javascript functions from aspx.cs? - javascript

I am working on an asp.net web app project, and I have a button which is using javascript for drop down menu:
<asp:Button ID="BtnPlant1" runat="server" Width="160px" BackColor="Transparent"
Height="40px" CssClass="buttonStyle" onmouseover="MM_showMenu(window.langT,0,40,null,'BtnPlant1');"
onmouseout=MM_startTimeout();/>
And I have a dropdown list for change drop down menus.
For example when dropdownlist.SelectedItem.Text == "langE" I want to change onmouseover to this:
onmouseover="MM_showMenu(window.langE,0,40,null,'BtnPlant1');"
// ^-- (langE, not langT)
How can I do this? Any idea? Thanks...

You should have jquery... so try something like this:
<asp:Button ID="BtnPlant1" runat="server" Width="160px" BackColor="Transparent"
Height="40px" CssClass="buttonStyle" onmouseover="showMenu()"
onmouseout=MM_startTimeout();/>
javascript:
function showMenu() {
if($('.dropdownlist').val() == "langE")
MM_showMenu(window.langE,0,40,null,'BtnPlant1');
else
MM_showMenu(window.langT,0,40,null,'BtnPlant1');
}
$('.dropdownlist').change(function() {
showMenu();
}
Not testet!....

The solution:
function showMenu() {
if($("#ddlistid option:selected").text() == "langE")
MM_showMenu(window.langE,0,40,null,'BtnPlant1');
else
MM_showMenu(window.langT,0,40,null,'BtnPlant1');
}

Related

ASP.NET can't resolve javascript function

How could I run javascript on changing value of ASPxComboBox?
I tried this:
<dx:ASPxComboBox ID="cbx_Organization" runat="server" ValueType="System.String"
AutoPostBack="True" OnSelectedIndexChanged="handleOrganizationChange()" Width="230px">
</dx:ASPxComboBox>
<script type="text/javascript">
function handleOrganizationChange() {
__doPostBack("<%= cbx_Organization.Value %>", "Load_Executives");
}
</script>
but Index.aspx does not contain a definition for handleOrganizationChange().
I think you are using inappropriate syntax. Instead of using OnSelectedIndexChanged attribute try using onchange="javascript:handleOrganizationChange()"attribute and that should work fine..
Try this one
<dx:ASPxComboBox ID="cbx_Organization" runat="server" ValueType="System.String" Width="230px"> <ClientSideEvents SelectedIndexChanged="function(s, e) { handleOrganizationChange(); }" />
</dx:ASPxComboBox>

How to enable/disable a button on parent modal popup from child in the IFrame using javascript

I am trying to disable/enable a button of the parent window from the child window.
The following is a snippet from the parent page.
<ajaxToolkit:ModalPopupExtender ID="mpeTest" runat="server"
CancelControlID="btnClose" PopupControlID="pnl1" TargetControlID="showMpe"/>
<asp:Panel ID="pnl1" runat="server" >
<ContentTemplate>
<iframe id="ContentIframe" runat="server">
<p>Your browser does not support iframes.</p>
</iframe>
</ContentTemplate>
<p class="submitButton">
<asp:Button ID="btnClose" runat="server" Text="Close" />
<asp:Button ID="btnTest" runat="server" Text="EnableDisable" />
</p>
</asp:Panel>
In the child page that is loaded in the iframe, I have a grid view with LinkButtons. I am attempting to get one of these LinkButtons to disable/enable the btnTest from the parent window.
I have tried many things but I can't seem to figure this out...
for example:
<script type="text/javascript" >
$(document).ready(function() {
jQuery('[id$="linkButtonDisable"]').click(function() {
window.parent.opener.document.getElementById("btnTest").disabled = true;
});
});
</script>
Can anyone please help me out. I am fairly new to this
Maybe you should try something like this...
$("#<%=linkButtonDisable.ClientID %>").click(function() {
//Option N#1 HTML Attribute
$("#<%=btnTest.ClientID %>").attr("disabled","disabled");
//Option 2 With jQueryMobile integration, the same it supposed to work if your using bootstrap, but I ignore the css class for disabling an element
$("#<%=btnTest.ClientID %>").addClass("ui-disabled");
//Also if you want to toggle states between disable/enable maybe this could work either...
var id = $("#<%=btnTest.ClientID %>");
var state = id.attr("disabled");
//Dunno if it's needed to catch if disabled attr it isn't set
if(state == "disabled") {
id.removeAttr("disabled");
} else {
id.attr("disabled","disabled");
}
});
Hope this help!...

Click event is not working in grid view in asp.net

I have one templete field inside grid view, code is written as below :
<asp:TemplateField HeaderStyle-Width="40px" HeaderStyle-Font-Underline="false" ItemStyle-HorizontalAlign="Center" HeaderText="" >
<ItemTemplate>
<a href="javascript:fillBankDetails(<%# CreateBankDetailsArray(DataBinder.Eval(Container, "DataItem")) %>);window.close();" >Select</a>
</ItemTemplate>
</asp:TemplateField>
and javascript function is written as below
function fillBankDetails(bankDetails) {
alert('Hello');
isSelected = true;
var a = JSON.parse(bankDetails);
window.returnValue = a[0];
}
When I click on select, click event is not firing. Did I have done any mistake. Please help in this.
Thanks in advance.
Try this code
<a href="javascript:fillBankDetails(<%# CreateBankDetailsArray(Eval("DataItem")) %>);window.close();" >Select</a>

How do i preform a Jquery function after drop down list change?

I'm struggling to move into the change function after i have made a change to my drop down list?
<script type="text/javascript" src="ICCMJScripts/jquery-1.7.1.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$("#ddRequestCategory").change(function () {
//Do something
});
});
</script>
Here is my drop down list.
<ICCM:ICCMDropDownList style="width:185px;" runat="server" ID="ddRequestCategory" name="ddRequestCategory" TabIndex="1" AppendDataBoundItems="true" >
<Items>
<asp:ListItem Value="" Text="" Selected="True" />
</Items>
</ICCM:ICCMDropDownList>
You need to use ClientID as the html gererated by asp.net has different id then you have assigned.
$("#<%= ddRequestCategory.ClientID %>").change(function () {
//Do something
});
If you are using .net framework 4 or above then you can use ClientIDMode="static" to get the same id in the generated html by asp.net.
Add this to the code behind in the form load.
DropDownListName.Attributes.Add("onchange", "jsFunctionName();");
When the DropDownList selectedItemIndex is changed then your function is called and you can do what ever you need from there.
Use ON function to trigger the event.
$(document).ready(function(){
$('#selectID').on('change', function(){
console.log($(this).val());
});
});
demo: http://jsfiddle.net/9eDS7/

How to avoid the page refresh at each server side event in asp.net?

I've designed a web page in asp.net. And in that page i placed html control too like <a> & <div>. I have written one java script function which is hiding the <div> when i'm clicking on the <a> tag. Its working fine. But when i'm clicking on the asp.net button then page refresh occur again. And it is loading my previous design of the page. I set the display:none of the <div> at the design time. so it is hiding my <div> again when occuring any other server side event. And i don't want let it happen.
Javascript function-
<script language="javascript" type="text/javascript">
function toggle5(showHideDiv, switchTag) {
try {
'<%Session["temp"] = "'+more+'"; %>';
var ele = document.getElementById(showHideDiv);
var imageEle = document.getElementById(switchTag);
if (ele.style.display == "block") {
ele.style.display = "none";
imageEle.innerHTML = 'More';
}
else {
ele.style.display = "block";
imageEle.innerHTML = 'Less';
}
}
catch (err) {
alert("Error");
}
}
</script>
html code is-
<div id="divSearch" style="float:left;height:100%;width:100%;">
<span style="float:right;height:27px;"><a id="displayText" href="#" onclick="javascript:toggle5('toggleText', 'displayText');">More</a></span>
</div>
<div id="toggleText" style="display:none;height:100%;width:100%;">
<div id="divCalls" style="width:24%;float:left;height:30%;">
<span style="float:left;width:100%;color:#3b5998;">
<asp:CheckBox ID="chkNoCall" runat="server" Text="No call made in "
AutoPostBack="True" oncheckedchanged="chkNoCall_CheckedChanged"/>
<asp:TextBox ID="txtNoCall" runat="server" Width="12%" Enabled="False"></asp:TextBox><span> days</span></span>
</div>
</div>
C#.net code of the Checkbox-
protected void chkNoCall_CheckedChanged(object sender, EventArgs e)
{
if (chkNoCall.Checked == true)
{
txtNoCall.Enabled = true;
}
else
{
txtNoCall.Enabled = false;
txtNoCall.Text = "";
}
}
How to solve this problem?
thanks
put this data inside the updatepanel like this
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<span style="float:left;width:100%;color:#3b5998;">
<asp:CheckBox ID="chkNoCall" runat="server" Text="No call made in "
AutoPostBack="True" oncheckedchanged="chkNoCall_CheckedChanged"/>
<asp:TextBox ID="txtNoCall" runat="server" Width="12%" Enabled="False"></asp:TextBox><span> days</span></span>
</ContentTemplate>
</asp:UpdatePanel>
hope this help
In your button click event, return false. this will prevent postback.
Use ajax to get the server side data instead of submitting the page.
Try one of the following:
remove runat=server from the component (a component with runat=Server always submits a form.
use standard html controls
use javascript for html controls
it it's a component with autopostback feature; make autopostback=false

Categories