Fancybox event is not fired - c#

i have my login in a fancybox and fancybox div is in a controller. problem is if click the button nothing happens event isnt fired.
this is my controller.ascx
<div id="inline1" style="width:400px;">
<ul class="forms">
<li class="inputfield"><asp:TextBox ID="kullanıcı_adi" runat="server"></asp:TextBox></li>
</ul>
<ul>
<li><asp:TextBox ID="sifre" runat="server"></asp:TextBox></li>
</ul>
<ul>
<li>
<asp:Button ID="Button1" runat="server" Text="Giriş Yap"
onclick="Login_Authenticate" />
<asp:Button ID="Button2" runat="server" Text="Vazgeç"/>
</li>
</ul>
</div>
and this is my cotroller.ascx.cs
protected void Login_Authenticate(object sender, EventArgs e)
{
bool authenticated = AuthenticateMe(kullanıcı_adi.Text, sifre.Text, true);
if (authenticated)
{
FormsAuthentication.RedirectFromLoginPage(kullanıcı_adi.Text, true);
}
}
and this is the default.aspx
<li class="gallery"><a id="various1" href="#inline1">Üye ol/Giriş Yap</a></li>
<div style="display: none;">
<co:c_login ID="id_c_login" runat="server" EnableViewState=true />
</div>
I found the solution. Same question asked before.
Fancybox - ASP.NET button not working Thank you for your answers.

A bit late, but it may help you.
This is because how fancybox works, when fancybox displays the div block, it creates temporary div block with your content and appends it to end of the body tag of the page, hence this generated temporary block is created outside form tag.
In a web page when you postback a page, the control which generates postback event must be within form tag to identify the page postback action.
To resolve this issue you can use a bit of javascript, create another button control but it should not be part of fancybox control, and on submit button within fancybox, fire click event of another created button (which will be inside form tag) with help of javascript.
That should solve your problem, please vote if it answer your question.

We can solve fancybox 2 event not firing issue by using parent property of fancybox.
for example -
$("#buttonClick").fancybox({
parent: "form:first",//Asp.net Button click event not working issue solved by using this statement
......your fancybox config options
});

Related

Using Modal Popup for Displaying aspx page inside another aspx page

I have the below code which I am using to open a aspx page inside a modal popup but the issue is as soon as I load the host page of the modal popup it is redirecting to the one which is inside the iFrame.
<cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panl1" TargetControlID="Button1"
CancelControlID="Button2" BackgroundCssClass="Background">
</cc1:ModalPopupExtender>
<asp:Panel ID="Panl1" runat="server" CssClass="Popup" align="center" Style="display: none">
<iframe style="width: 350px; height: 300px;" id="irm1" src="PayrollScope.aspx?id=49437" runat="server"></iframe>
<br />
<asp:Button ID="Button2" runat="server" Text="Close" />
</asp:Panel>
So the sequence is
MainPage.aspx -> Click PopUp -> Load PayrollScope.aspx inside the modal
But as soon as I hit the MainPage.aspx it is redirecting to PayrollScope.aspx. I tried to use jQuery modal popup also but the same issue is happening. Can someone please tell me why it's redirecting.
Thanks
If you use jQuery dialog to load that other page?
Well, it will display, but THEN if any code in the page has a post back, then yes, it will re-direct to that page.(jQuery dialog simply pulls the whole other page right into that div and "merges" it into your current page's dom. So, you can display the page, and no re-direct will occur. However, any server side button event code (button press, or even say a after update event of editing a text box (on changed) will cause a post back. And any post-back WILL thus cause the page to re-direct (after all any code behind event does send the WHOLE page back and the URL to IIS. So, it much depends on if you JUST displaying that page, or if you want/need/have user interaction on the 2nd page loaded as a dialog.
So, dump the ajax popup and controls reverence to the id of the popup. (don't try jQuery an the ajaxtool kit to "both" try and pop up a control/div - they tend to not play nice with each other.
I do suggest using jQuery.
This would work (but with above post back issues in mind).
<body>
<form id="form1" runat="server">
<br />
<asp:Button ID="Button1" runat="server" Text="Show page as dialog" OnClientClick="showpage1();return false"/>
<div id="poppage" runat="server" style="display:none">
</div>
<link href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.min.css" rel="stylesheet" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script>
function showpage1() {
var mydiv = $('#poppage');
mydiv.dialog({
autoOpen: false, modal: true, title: 'My cool other page', width: '50%',
position: { my: 'top', at: 'top+150' }
});
mydiv.load('MyOtherPage.aspx');
// Open the dialog
mydiv.dialog('open');
}
So, above will LOAD the other page (into that div), thus pop up the 2nd page when you click on the above button. (and note the return=false). If you have any postback on the page, then everything will quite much blow out the dialog. (and this also means the 2nd page we display (load) as per above.
However, if you need interaction on that 2nd page? (have to click on buttons etc.).
Then the idea of a iframe is a VERY good idea.
So, you have same as before, but we now don't "load" the page using jQuery.ui, but JUST display (and thus pop up) the div with a iframe you placed inside.
So,the div becomes this:
<div id="poppage" runat="server" style="display:none">
<iframe src="MyOtherPage.aspx" class="auto-style1"></iframe>
</div>
and the js code becomes this:
function showpage1() {
var mydiv = $('#poppage');
mydiv.dialog({
autoOpen: false, modal: true, title: 'My cool other page', width: '50%',
position: { my: 'top', at: 'top+150' }
});
// Open the dialog
mydiv.dialog('open');
}
So, now the above will just display that other page in the div, and since it is a iFrame, then you can interact - and post backs in that iframe should work just fine.
So, remove the ajax panel stuff - give jQuery.ui a try. I used the ajaxtool kit stuff, but for displaying another whole page in a dialog, then i found jQuery.ui seems to work a lot better

Using ASP.NET to Hide an HTML Div

I am using ASP.NET for a web page in order to make some server calls that involve looking up user organization information. Based on that information, we need to either hide or display a div. In the header I have a C# function that definitely runs. I have tried the following lines to hide the div.
divID.Style.Add("display","none");
and
divID.Visible = false;
In the body, I am currently using an asp:Panel that runs at server and contains the id "divID". No matter what I do, I can't get the div to hide (without manually putting the styling in). I tried putting the scripts before and after the body, and it didn't make a difference. Any suggestions on the best way to do this would be appreciated.
EDIT:
Here is the C# initiating code.
<script runat="server" language="C#">
void getUserInfo(Object sender, EventArgs ev){
The rest of the C# code is irrelevant, but the relevant line shown above is definitely being run.
The HTML portion looks something like this.
<asp:Panel runat="server" id="divID" style="width:200px; height:130px; ">
<div style="text-align:center">Test Data</div>
</asp:Panel>
C# code is always compiled and run from the server-side, and so cannot impact the state of a page once rendered unless you use postbacks or callbacks. If you want to change the visible state of a control on the client-side, you will need to use Javascript on the client side (possibly triggered by a button click) to show and hide the control.
As an example, check out the solution at the link below.
https://forums.asp.net/t/1603211.aspx?Show+hide+div+on+button+click+without+postback
<script type="text/javascript">
function ToggleDiv(Flag) {
if (Flag == "first") {
document.getElementById('dvFirstDiv').style.display = 'block';
document.getElementById('dvSecondDiv').style.display = 'none';
}
else {
document.getElementById('dvFirstDiv').style.display = 'none';
document.getElementById('dvSecondDiv').style.display = 'block';
}
}
</script>
<asp:Button ID="btn" runat="server" Text="Show First Div"
OnClientClick="ToggleDiv('first');return false;" />
<asp:Button ID="Button1" runat="server" Text="Show Second Div"
OnClientClick="ToggleDiv('second');return false;" />
<br />
<div id="dvFirstDiv" style="display: none;">
First Div
</div>
<div id="dvSecondDiv" style="display: none;">
Second Div
</div>
In the header I have a C# function that definitely runs.
If you're talking about the HTML page header - no, it definitely not running. C# code is executed only server side.
Based on your post, I'm assuming we're talking WebForms here and yo have a script block in your aspx file. While this is fine, I recommend placing the server-side code into a code behind file.
So all you need to do is to add a handler for the PreRender phase of the page life cycle and place your logic for showing/hiding the div in there.
public void Page_Prerender(object sender, EventArgs e)
{
divID.Visible = false;
' OR
'divID.Style.Add("display","none");
}
Note that setting the Visible property of a WebForms control excludes the control from rendering to the page, whilst setting display: none renders it as HTML but it isn't displayed on the page.
Try in backcode: divID.Controls.clear();
This worked for me.

how to add hide event to the button in webform?

im trying to hide div by clicking the button, but it does hide it for a second and return the div (looks like it refreshing page).here is my html code :
<div id="page">
<p>First Paragraph</p>
<p>Second Paragraph</p>
<p>Yet one more Paragraph</p>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
and here is my jquery code:
$(document).ready(function () {
$("#Button1").click(function () {
$("#page").hide();
});
});
What Rick said in his answer AND you need to add Type="Button" to your button.
<Button ID="Button1" type="button">Button</button>
The default button type is submit, which will cause the page refresh. AND, as Rick mentioned, ASP buttons will also submit. So, you need to use an HTML button and set the type="button" attribute.
From MDN
The type of the button. Possible values are:
submit: The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute
is dynamically changed to an empty or invalid value.
reset: The button resets all the controls to their initial values.
button: The button has no default behavior. It can have client-side scripts associated with the element's events, which are
triggered when the events occur.
An ASP Button with runat="server" causes a server post-back. If you aren't going to be acting on that click from the server, just use a client-side button like:
<button id="Button1" type="button">Button</button>
Set the client id mode to static on the button, then it'll work. It's not working because that hasn't been specified so the name is changing.
<asp:Button ID="Button1" ClientIDMode ="Static" runat="server" Text="Button" />
If you wanted to disable the postback to simply hide something without processing anything, then just using a client side button is the best option.

Event in repeater not fired until page postback by another control in asp.net c#!

Why My Event as link button event or item command not fired until i post back page with another control in page.
for example in this code:
<div id="pagination">
<span class="all" runat="server" id="CurrentPage">Total Pages</span>
<asp:Repeater ID="RPTPaging" runat="server" Visible="false" OnItemDataBound="RPTPaging_ItemDataBound" OnItemCommand="RPTPaging_ItemCommand">
<ItemTemplate>
<asp:LinkButton ID="BtnPage" CssClass="inactive" CommandName="Page" CommandArgument="<%# Container.DataItem %>" runat="server" Text="<%# Container.DataItem %>"></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
</div>
related to this question
Why Repeater ItemCommand Doesn't fire, even if i don't rebind by post back?
i found when i click on link button in this repeater nothing happened,but after i click on empty input button on page, after post back a page changed corectlly.
Dear Expert After 2 day finally i figure out why my page doesn't post back.
after i tried to post back my button manually with java script and i failed. i tried to trace the script and i found this Error with firebug:
TypeError: theForm.submit is not a function
theForm.submit();
when i google it i found i have a button in my MasterPage with id="Submit" and as
"submit is not a function" means that you named your submit button or some other element submit. Rename the button to btnSubmit and your call will magically work.
When you name the button submit, you override the submit() function on the form.
So This Problem Resolved. Thanks to all.

Calling c# function from javascript

I want to call a c# function from my javascript function.
I have a link button in my ascx (please see the code below). The problem is that if you press enter in firefox is not working however it is working fine in internet explorer.
<li class="clearfix border_top">
<label for="title" class="first_column bold">Search For</label>
<div class="contactUs_details">
<input type="text" id="advanced_txtBox1" name="advanced_txtBox1" class="searchbox" runat="server" style="width:300px;" />
<asp:CheckBox ID="chkSearchBDJ" runat="server" Text="Search BDJ" CssClass="checkboxlistnoborder" />
</div>
</li>
<div class="img_SearchNow">
<asp:LinkButton ID="btnSearchNow" CausesValidation="true" runat="server" OnClick="btnSearchNow_Click"></asp:LinkButton>
</div>
I have linkButton see above on which I have called on c# function on Click, But if you pree some text in above textbox and press "Enter" it should automatically call function "btnSearchNow_Click". It is working fine in IE but not working in Firefox.
A javascript function to click a button...
function clickMyButton() {
var ele = document.getElementById('btnSearchNow');
if ((ele !== null) && (ele != 'undefined')) {
ele.click();
}
}
The wording of your question could use some cleaning up, or some additional information.
If you are looking for pseudo-submit behavior from inside a text box, take a look at this post. Submit Login control button when I hit Enter
You will have to generate the javascript from the server side, since you are using an ASCX and the ID's are not the ones you defined.
You need to have a submit type on the page for it to work properly in firefox.
<input id="mysubmit" runat="server" type="submit" onclick="return false;" style="display: none;" />
Edit: Here's a google cached page that has more information. The original post doesn't seem to be available ATM, but good old google had it.

Categories

Resources