OnClick and OnClientClick not working together in RadButton - onclick

IN RadButton OnClick Event and OnClient Event are not working together. Javascript is not called by OnClient Click in radbutton. I also use RadAjaxSetting.
<script language="javascript" type="text/javascript">
form_dirty = false;
calenderclink = false;
window.onbeforeunload = askUser;
function setSaveEnable() {
document.getElementById('ctl00_ContentPlaceHolder1_btnSave_85').disabled = false;
form_dirty = true;
calenderclink = false;
}
function form_dirty_true() {
document.getElementById('ctl00_ContentPlaceHolder1_btnSave_85').disabled = false;
form_dirty = true;
calenderclink = false;
}
function form_dirty_false() {
form_dirty = false;
calenderclink = false;
Calnederdirty = false;
}
function setSaveEnableforCalender() {
form_dirty = true;
calenderclink = true;
}
function askUser(evt) {
var vtxtSiv = '<%=HndDiscurdMessage.ClientID%>';
var message = document.getElementById(vtxtSiv).value;
if (form_dirty == true && calenderclink == false) {
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
}
return message;
}
else if (form_dirty == true && calenderclink == true) {
if (document.getElementById('ctl00_ContentPlaceHolder1_rdpWishDate').value != null) {
form_dirty = true;
calenderclink = true;
}
}
}
function ClearAlert() {
var _dvAlert = document.getElementById("<%# dvAlert.ClientID %>");
_dvAlert.attributes[2].value = "display: none;";
form_dirty_true();
}
</script>
<telerik:RadButton ID="btnSave_85" runat="server" CssClass="btnMain btngreen right topRightBtn" OnClientClick="form_dirty_false();" SingleClick="true"
Text="Save" OnClick="btnSave_Click" ></telerik:RadButton>
ONClick is working properly but on clientclick is not working.

Try this out.
<telerik:RadButton ID="btnSave_85" runat="server" CssClass="btnMain btngreen right topRightBtn" OnClientClick="form_dirty_false;" SingleClick="true"
Text="Save" OnClick="btnSave_Click" ></telerik:RadButton>
Then in your javascript have this:
function form_dirty_false(s,a) {
form_dirty_false(); // your original code
}

Related

Updatepanel for LinkButton Not Working Well in Asp.net

i have a task for Adding control for linkbutton click.
for this i i have created 5 Uploadcontrols with existing 5 controls by giving visible false.
here i am doing for every click one control is showing from server side.
When i click liknbutton everytime postingback..so to restrict this i have added Updatepanel to link button as given below
<asp:UpdatePanel ID="uploadaddmorepic" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:LinkButton ID="lnkaddmorepics" runat="server" Text="Add More Pics"
onclick="lnkaddmorepics_Click"></asp:LinkButton>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lnkaddmorepics" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
in link button click
protected void lnkaddmorepics_Click(object sender, EventArgs e)
{
int rowCount = 0;
//initialize a session.
rowCount = Convert.ToInt32(Session["clicks"]);
rowCount++;
//In each button clic save the numbers into the session.
Session["clicks"] = rowCount;
//Create the textboxes and labels each time the button is clicked.
for (int i = 0; i < rowCount; i++)
{
if (i == 0)
{
lblupload6.Visible = true;
FileUpload5.Visible = true;
ddlimage5title.Visible = true;
lblforupload6.Visible = true;
}
if (i == 1)
{
lblforuplaod7.Visible = true;
lblforupload6.Visible = true;
ddlimage6title.Visible = true;
FileUpload6.Visible = true;
}
if (i == 2)
{
lblforuplaod8.Visible = true;
lblforuplaod7.Visible = true;
ddlimage7title.Visible = true;
FileUpload7.Visible = true;
}
if (i == 3)
{
lblforuplaod9.Visible = true;
lblforuplaod8.Visible = true;
ddlimage8title.Visible = true;
FileUpload8.Visible = true;
}
if (i == 4)
{
lblforuplaod10.Visible = true;
lblforuplaod9.Visible = true;
ddlimage9title.Visible = true;
FileUpload9.Visible = true;
}
}
getting firing but controls are not showing for every click..plz help me out

how to pass id of a label to a function in c#.net

i have the following label.
<asp:Label ID="lbl_Modification" runat="server" Font-Bold="False" Font-Size="Small" ForeColor="#FF3300" Visible="False" Width="300px"></asp:Label>
<asp:Label ID="lbl_Message" runat="server" Font-Bold="False" Font-Size="Small" ForeColor="#FF3300" Visible="False" Width="300px"></asp:Label>
i want to pass id of the above label to the following method.
public bool date_Validation(DateTime t_Start_Date,DateTime t_End_Date,DateTime t_View_From)
{
#region date_Validation
try
{
if (t_Start_Date.Date < DateTime.Today)
{
lbl_Modification.Visible = true;
lbl_Modification.Text = "Date cannot be lesser than the Current Date";
return false;
}
else if (t_End_Date.Date < t_Start_Date)
{
lbl_Modification.Visible = true;
lbl_Modification.Text = "Invalid End Date";
return false;
}
else if (t_View_From.Date < DateTime.Today || t_View_From.Date >= t_Start_Date.Date)
{
lbl_Modification.Visible = true;
lbl_Modification.Text = "view Date cannot be greater than the Start Date or lesser than Current date";
return false;
}
return true;
}
catch (Exception e)
{
throw e;
}
#endregion
}
How i can i do this.
Please someone help me to do this.
public bool date_Validation(DateTime t_Start_Date,DateTime t_End_Date,DateTime t_View_From, Label lblModification)
{
// Method Content
}
//Call this method with your label parameter
date_Validation(startdate,enddate,viewform,lbl_Modification)
//lbl_Modification -> its your label name
Control's ID is a string, if you want to pass it as an extra parameter then change your method declaration to accept an additional param
public bool date_Validation(DateTime t_Start_Date,DateTime t_End_Date,DateTime t_View_From, string LabelID)
{
#region date_Validation
try
{
if (t_Start_Date.Date < DateTime.Today)
{
//Find the control here
var label=This.FindControl(LabelID);
lbl_Modification.Visible = true;
lbl_Modification.Text = "Date cannot be lesser than the Current Date";
return false;
}
else if (t_End_Date.Date < t_Start_Date)
{
lbl_Modification.Visible = true;
lbl_Modification.Text = "Invalid End Date";
return false;
}
else if (t_View_From.Date < DateTime.Today || t_View_From.Date >= t_Start_Date.Date)
{
lbl_Modification.Visible = true;
lbl_Modification.Text = "view Date cannot be greater than the Start Date or lesser than Current date";
return false;
}
return true;
}
catch (Exception e)
{
throw e;
}
#endregion
}
then your calling code would be something like
var isValid=date_Validation(startdate, enddate, "lbl_Modification");

ASP.NET Check UserName Availability using ClientSideEvents

This is the first post for me in this the greatest website.
Is there any possibility to change isValid property from OnCheckUserName function?If so how can I do that?
Actually in this example there is a code block which use web service:
<script type="text/javascript">
function OnloginIDValidation(s, e) {
if (e.value.toString().length > 0) {
e.errorText = "UserName is not available";
PageMethods.CheckUserName(e.value.toString(), OnCheckUserName);
}
}
function OnCheckUserName(unavailable) {
if (unavailable == true) {
e.isValid = true;
}
else if (unavailable != true) {
e.isValid = false;
}
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<dx:ASPxTextBox ID="txt_loginID" runat="server" AssociatedControlID="txt_loginID">
<InvalidStyle BackColor="#FFF5F5">
<Border BorderColor="Red" BorderStyle="Solid" BorderWidth="1px" />
</InvalidStyle>
<ClientSideEvents Validation="OnloginIDValidation" />
</dx:ASPxTextBox>
</asp:Content>
[WebMethod]
public static bool CheckUserName(string userName)
{
if (Membership.GetUser(userName) != null)
{
return true;
}
else
{
return false;
}
}
private void ApplyValidationSummarySettings()
{
vsValidationSummary1.RenderMode = (ValidationSummaryRenderMode)Enum.Parse(typeof(ValidationSummaryRenderMode), "BulletedList");
vsValidationSummary1.ShowErrorAsLink = true;
}
private void ApplyEditorsSettings()
{
ASPxEdit[] editors = new ASPxEdit[] {txt_loginID};
foreach (ASPxEdit editor in editors)
{
editor.ValidationSettings.ValidateOnLeave = true;
editor.ValidationSettings.SetFocusOnError = true;
}
}
It doesn't work
I hope to help me how can i fix it.
thanks
Set ASPxTextBox.ClientInstanceName attribute to some value, e.g. textBox1. Then use ASPxClientTextBox.SetIsValid method in OnCheckUserName method.
Like this:
function OnCheckUserName(unavailable) {
textBox1.SetIsValid(unavailable == true);
}
Check below links using JQuery & AJAX for username availability
http://www.aspsnippets.com/Articles/Check-UserName-Availability-in-ASP.Net-using-JQuery.aspx
http://www.aspsnippets.com/Articles/Check-Username-Availability-in-ASP.Net-using-AJAX-PageMethods.aspx

asp.net button click event not working with firefox

Following is the code that i am using. It work in IE but the button click event is not generated properly in firefox:
function trapEnter(btn,hdn, event) {
var key;
var isIE = true;
debugger;
if (window.event) {
key = window.event.keyCode; //IE
isIE = true;
}
else {
key = event.which; //firefox
isIE = false;
}
if (key == 13) {
var btn = document.getElementById(btn);
if (btn != null) { //If we find the button click it
document.getElementById(hdn).value = '1'
btn.click();
key = 0;
}
}
}
I think your function has the wrong parameters. Try this:
function trapEnter(e) {
e = e || window.event || event;
var code = e.charCode || e.keyCode || e.which;
if (code == 13) {
var btn = document.getElementById('<%= YourButtonID.ClientID %>');
if (btn != null) { //If we find the button click it
document.getElementById(hdn).value = '1';
btn.click();
key = 0;
}
}
}

javascript inside updatepanel

im using javascript in asp.net gridview
<script type="text/javascript">
var currentRowId = 0;
function SelectRow()
{
if (event.keyCode == 40)
MarkRow(currentRowId+1);
else if (event.keyCode == 38)
MarkRow(currentRowId-1);
}
function MarkRow(rowId)
{
if (document.getElementById(rowId) == null)
return;
if (document.getElementById(currentRowId) != null )
document.getElementById(currentRowId).style.backgroundColor = '#ffffff';
currentRowId = rowId;
document.getElementById(rowId).style.backgroundColor = '#ff0000';
}
</script>
<script type="text/javascript">
var TargetBaseControl = null;
window.onload = function()
{
try
{
//get target base control.
TargetBaseControl =
document.getElementById('<%= this.GridView1.ClientID %>');
}
catch(err)
{
TargetBaseControl = null;
}
}
function TestCheckBox()
{
if(TargetBaseControl == null) return false;
//get target child control.
var TargetChildControl = "chkSelect";
//get all the control of the type INPUT in the base control.
var Inputs = TargetBaseControl.getElementsByTagName("input");
for(var n = 0; n < Inputs.length; ++n)
if(Inputs[n].type == 'checkbox' &&
Inputs[n].id.indexOf(TargetChildControl,0) >= 0 &&
Inputs[n].checked)
return true;
alert('Select at least one checkbox!');
return false;
}
</script>
button control:
" Width="80px" CssClass="button" />
im using ajax update panel in gridview ...i control postback level but the script is not working inside the updatepanel
In your button_clicked event, you could use this method
ScriptManager.RegisterClientScriptBlock(Control, Type, String, String, Boolean)
More info below
http://msdn.microsoft.com/en-us/library/bb350750.aspx

Resources