I have Onclientclick event attached to the button in serverside code like below,
TopPanelButton.OnClientClick = string.Format("if(!ValidData({0},{1},{2},{3})) return false;", txtOD.ClientID, radCmbOD.ClientID, txtgetMe.ClientID, RadAjaxLoadingPanel1.ClientID);
Also, the onClick event is attached for the same button in the aspx page,
<asp:Button ID="TopPanelButton" runat="server" Text="Go"
CssClass="CBtn1" Width="30px" Height="21px" OnClick="TopPanelButton_Click" />
The serverside click event should fire if the onclientclick return true. The "ValidateData()" function is called to validate the entries in the form.
This code is working fine in IE. But in Firefox, both events are not firig. If I comment the "TopPanelButton.OnClientClick =..." code then onClick event is firing.
Where can I apply this code Page.ClientScript.GetPostBackEventReference() in my code below.
TopPanelButton.OnClientClick = string.Format("if(!ValidData({0},{1},{2},{3})) return false;", txtOD.ClientID, radCmbOD.ClientID, txtgetMe.ClientID, RadAjaxLoadingPanel1.ClientID);
Firefox is not calling the ValidData function. I put alert inside the javascript, but alert message is not shown in Firefox. But IE shows the alert message.
My validData function:
function ValidData(txtOND, ddlOND, txtgetMe, aPanel) {
alert("Entered");
if (!ValidNumber(txtgetMe)) {
aPanel.hide();
return false;
}
if (ddlOND.value == "Origin" || ddlOND.value == "Destination") {
if (!ValidOriginOrDestination(txtOND, ddlOND.value)) {
aPanel.hide();
return false;
}
}
else if (ddlOND.value == "O&D") {
if (!ValidOND(txtOND)) {
aPanel.hide();
return false;
}
}
if (ddlOND.value == "Region Starting with" || ddlOND.value == "Country Starting with" || ddlOND.value == "Budget Station Starting with") {
if (txtOND.value.length == 0) {
radalert("Enter a value for " + ddlOND.value);
aPanel.hide();
return;
}
}
aPanel.show();
return true;
}
FireFox not handling both an OnClientClick and OnClick event (although Internet Explorer handled it fine). To fix this there is a method
Page.ClientScript.GetPostBackEventReference()
that can be used that generates client side Javascript for doing a postback to controls.So the following code will hide everything on the page except the loading graphic, and also call the btnSubmit postback method. The reason it returns false is that otherwise Internet Explorer would call the server side OnClick method twice.