What exactly isn't working? You can't click the button and you didn't explicitly tell js or jquery to click the button. You can do that with $('#' + dugme).click();
"What I hear, I forget; What I see, I remember; What I do, I understand." --Confucius
Remeber to Mark as Answer if this post helped you.
Let me explain why I am trying to do this. May be this would be more helpful.
I have a textbox and onblur of this textbox I am doing couple of stuff via jquery as follows. I am checking database if there are records and if there are records, I am trying to pop up a gridview, displaying those records.
$(document).ready(function ($) {
var drp = "<%= DropDownList_faturaEdilecekKisi.ClientID %>";
var bayi = "<%= bayi.ClientID %>";
var ad = "<%= ad.ClientID %>";
$("#" + drp).change(function () {
// alert($("#" + drp).val()); //Added to test whether the event is fired or not
if ($("#" + drp).val() == "1") {
$("#" + bayi).show();
$("#" + ad).show();
}
else {
$("#" + bayi).hide();
$("#" + ad).hide();
}
});
});
$(document).ready(function ($) {
var bayino = "<%= TextBox_bayino.ClientID %>";
var dugme = "<%= Button1.ClientID %>";
$("#" + bayino).live('blur', function () {
if ($("#" + bayino).val() != '') {
alert("POST");
$('#' + dugme).click();
jQuery.ajax({
type: "POST",
async: false,
url: "TerminalHasar.aspx/IsDamagedVendor",
data: "{bayino: '" + $("#" + bayino).val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
error: OnError
});
}
});
});
var grid = "<%= grid.ClientID %>";
var bayiadi = "<%= TextBox_bayiadi.ClientID %>";
function OnSuccess(response) {
alert(response.d);
if (response.d) {
$("#" + grid).dialog({
resizable: false,
height: 230,
width: 650,
modal: true,
title: "Hasar / Kayıp-Çalıntı Kaydı",
buttons: {
"Continue": function () {
$(this).dialog("close");
},
Cancel: function () {
$(this).dialog("close");
$(window.location).attr('href', 'http://www.google.com');
}
}
});
}
}
function OnError(response) {
alert(11);
jQuery.ajax({
type: "POST",
async: false,
url: "TerminalHasar.aspx/OnBlurError",
data: "{msg: '" + response.d + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json"
});
}
The problem is TextBox_bayino, is the textbox which I am handling onblur and in the gridview, in order to get the records I need to set the value of this textbox to control parameter. So before I display this pop up on the page, I need to bind this gridview
somehow. This is my issue.
How can I solve this?
Best Regards.
Keep your friends close and your enemies even closer
From what I can tell, it looks like you are walking over yourself in code. You have a textbox with a server-side textchanged event AND a javascript blur event that then calls some javascript. In that javascript you have a server-side button being clicked
that will cause a post-back AND an AJAX call to get some server data.
You need to look at the order of events that you are actually firing versus what you want to accomplish. Validation is good to have both server-side and client-side, but trying to perform multiple actions on a control both server-side and client-side is
going to get you into trouble.
My suggestion is that you map out a logical flow of what you want to happen with the data and what user events trigger the flow. Then determine if you are going to handle that event client-side or server-side. Once you make those decisions you can clean
up your code.
"What I hear, I forget; What I see, I remember; What I do, I understand." --Confucius
Remeber to Mark as Answer if this post helped you.
cenk1536
Contributor
2501 Points
2115 Posts
JQuery Click Problem on display: none;
Dec 19, 2012 07:56 PM|LINK
Hi,
I would like to use jquery click event as follows, but it did not work! How can I fix this?
Best Regards.
var dugme = "<%= Button1.ClientID %>"; $("#" + dugme).live('click', function () { alert("Clicked"); });grundebar
Contributor
4515 Points
726 Posts
Re: JQuery Click Problem on display: none;
Dec 19, 2012 08:12 PM|LINK
What exactly isn't working? You can't click the button and you didn't explicitly tell js or jquery to click the button. You can do that with $('#' + dugme).click();
Remeber to Mark as Answer if this post helped you.
asteranup
All-Star
30184 Points
4906 Posts
Re: JQuery Click Problem on display: none;
Dec 20, 2012 03:57 AM|LINK
Hi,
If you are looking for serverside click event from jquery, you can try this-
http://delicious.com/anupdg/__dopostback+button
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
alankarp
Contributor
2042 Points
345 Posts
Re: JQuery Click Problem on display: none;
Dec 20, 2012 04:22 AM|LINK
Try below code
$(function() { var fn=function(){ alert("Clicked"); }; var dugme = "<%= Button1.ClientID %>"; $("#" + dugme).click(fn); });refer:
http://jsfiddle.net/YTvye/
Profile
cenk1536
Contributor
2501 Points
2115 Posts
Re: JQuery Click Problem on display: none;
Dec 20, 2012 05:44 AM|LINK
Hi,
Let me explain why I am trying to do this. May be this would be more helpful.
I have a textbox and onblur of this textbox I am doing couple of stuff via jquery as follows. I am checking database if there are records and if there are records, I am trying to pop up a gridview, displaying those records.
$(document).ready(function ($) { var drp = "<%= DropDownList_faturaEdilecekKisi.ClientID %>"; var bayi = "<%= bayi.ClientID %>"; var ad = "<%= ad.ClientID %>"; $("#" + drp).change(function () { // alert($("#" + drp).val()); //Added to test whether the event is fired or not if ($("#" + drp).val() == "1") { $("#" + bayi).show(); $("#" + ad).show(); } else { $("#" + bayi).hide(); $("#" + ad).hide(); } }); }); $(document).ready(function ($) { var bayino = "<%= TextBox_bayino.ClientID %>"; var dugme = "<%= Button1.ClientID %>"; $("#" + bayino).live('blur', function () { if ($("#" + bayino).val() != '') { alert("POST"); $('#' + dugme).click(); jQuery.ajax({ type: "POST", async: false, url: "TerminalHasar.aspx/IsDamagedVendor", data: "{bayino: '" + $("#" + bayino).val() + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: OnSuccess, error: OnError }); } }); }); var grid = "<%= grid.ClientID %>"; var bayiadi = "<%= TextBox_bayiadi.ClientID %>"; function OnSuccess(response) { alert(response.d); if (response.d) { $("#" + grid).dialog({ resizable: false, height: 230, width: 650, modal: true, title: "Hasar / Kayıp-Çalıntı Kaydı", buttons: { "Continue": function () { $(this).dialog("close"); }, Cancel: function () { $(this).dialog("close"); $(window.location).attr('href', 'http://www.google.com'); } } }); } } function OnError(response) { alert(11); jQuery.ajax({ type: "POST", async: false, url: "TerminalHasar.aspx/OnBlurError", data: "{msg: '" + response.d + "'}", contentType: "application/json; charset=utf-8", dataType: "json" }); }Here is the gridview:
<div id="grid" runat="server" style="display: none;"> <asp:UpdatePanel ID="HasarUpdatePanel" runat="server"> <ContentTemplate> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" ShowHeaderWhenEmpty="True" AllowPaging="True" Width="600px"> <EmptyDataTemplate> Kayıt Bulunamadı. </EmptyDataTemplate> <Columns> <asp:BoundField DataField="Talebi_Yapan" HeaderText="Talebi Yapan"> <ItemStyle Font-Bold="True" /> </asp:BoundField> <asp:BoundField DataField="Talep_Zamanı" HeaderText="Talep Zamanı"> <ItemStyle Font-Bold="True" /> </asp:BoundField> <asp:BoundField DataField="BayiNo" HeaderText="Bayi No"> <ItemStyle Font-Bold="True" /> </asp:BoundField> <asp:BoundField DataField="HasarTipi" HeaderText="Hasar Tipi"> <ItemStyle Font-Bold="True" /> </asp:BoundField> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:EformsConnectionString %>" ProviderName="<%$ ConnectionStrings:EformsConnectionString.ProviderName %>" SelectCommand="select u.Name AS 'Talebi_Yapan', CONVERT(CHAR(10),th.CreationDate,104) + SUBSTRING(CONVERT(varchar,th.CreationDate,113),12,9) AS 'Talep_Zamanı',thk.BayiNo,thht.HasarTipi from Eform_TerminalHasar th INNER JOIN Eform_TerminalHasar_Kalem thk ON th.EFormID = thk.EformID INNER JOIN Eform_TerminalHasar_HasarTipi thht ON thk.HasarTipi = thht.HasarTipiID INNER JOIN Eform_TerminalHasar_FaturaEdilecekKisi thf ON thk.KimeFaturaEdilecek = thf.KisiTipiID INNER JOIN Users u ON th.CreatedBy = u.SAMAccountName where thk.BayiNo = @BayiNo"> <SelectParameters> <asp:ControlParameter Name="BayiNo" ControlID="TextBox_bayino" PropertyName="Text" DefaultValue=" " /> </SelectParameters> </asp:SqlDataSource> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="TextBox_bayino" EventName="TextChanged" /> </Triggers> </asp:UpdatePanel> </div>The problem is TextBox_bayino, is the textbox which I am handling onblur and in the gridview, in order to get the records I need to set the value of this textbox to control parameter. So before I display this pop up on the page, I need to bind this gridview somehow. This is my issue.
How can I solve this?
Best Regards.
grundebar
Contributor
4515 Points
726 Posts
Re: JQuery Click Problem on display: none;
Dec 20, 2012 02:54 PM|LINK
From what I can tell, it looks like you are walking over yourself in code. You have a textbox with a server-side textchanged event AND a javascript blur event that then calls some javascript. In that javascript you have a server-side button being clicked that will cause a post-back AND an AJAX call to get some server data.
You need to look at the order of events that you are actually firing versus what you want to accomplish. Validation is good to have both server-side and client-side, but trying to perform multiple actions on a control both server-side and client-side is going to get you into trouble.
My suggestion is that you map out a logical flow of what you want to happen with the data and what user events trigger the flow. Then determine if you are going to handle that event client-side or server-side. Once you make those decisions you can clean up your code.
Remeber to Mark as Answer if this post helped you.