jQuery's nyroModal with ASP.NET - asp.net

I'm using nyroModal plugin. By simply putting a setup scripts in the head tag and define a class attribute with nyroModal will make that link open as a modal window.
Show
Now, Page1.aspx will open in a modal window. This page has a simple asp:button having a OnClick defined with empty body:
<asp:button ID="btn" runat="server" OnClick="btn_Click"/>
void btn_Click(Object sender, EventArgs e) { }
If we click on the above link a window appears with a button and when I click on that button modal windows disappears (or break) and redirected to Page1.aspx.
Any idea, why is this happening?

Try adding the following:
jQuery(function ($) { jQuery('.nyroModal').nyroModal({ 'blocker': '#Form' }); });
replace #Form with aspForm or whatever your form name is.

Related

ASP.NET, Automatically make button click from page load

Is there a way to make a button click event run from the page load?
Yes, you can do that.
if your button has runat="server" you can access it from codebehind.
you could insert a click action on the button in the page_load event. but it's better to create a function with all actions to call both from button click and page_load.
<asp:Button id="btn1">Click here</asp:Button>
void Page_Load(object source, EventArgs e)
{
doThis();
}
void btn1_click()
{
doThis();
}
void doThis()
{
//click actions
}
Another way to do it is by javascript. find the button when document is ready and fire the click on the button.
You could wrap the logic behind the button click event in a function and call that function from the page load.

I get correct redirection after clicking on ASP.NET button but not in a new window as specified

Clicking on ASP.NET button redirects to correct website but on the same tab, not in a new tab what i need to do. What's wrong with the code OnClientClick="aspnetForm.target ='_blank';" below? Why it is not enough alone and what else need to be done?
The following ASP.NET code for the button control is:
<asp:Button ID="btnGenerateReport" runat="server" Text="Generate Report"
OnClick="btnGenerate_Click" OnClientClick="aspnetForm.target ='_blank';" />
I know two methods for redirecting the page to new tab in asp
1) The first method which you are already using and it works also. Make an onclientclick event of Button and on code behind of Button
Click write the following code:-
button.OnClientClick = "aspnetForm.target='_blank'"; Response.Redirect("yourpage.aspx");
2)You can also use javascript
button.Attributes.Add("onclick", "window.open('yourpage.aspx');return false;");
Both the method will redirect your page to new tab on clicking the button.
The error with your code is OnClientClick = "aspnetForm.target='_blank;'" remove the semicolon after '_blank' and it will work
If you are looking out for server side code to open a new window on Button Click, then here's how to do so.
Add the following script to the section of your page
<script language="javascript" type="text/javascript">
function openNewWin(url) {
var x = window.open(url, 'mynewwin', 'width=600,height=600,toolbar=1');
x.focus();
}
</script>
Then add a Button Control in the following manner
<asp:Button ID="btnOpenPop" runat="server" Text="Open Pop"
onclick="btnOpenPop_Click" />
Finally add some code in the code behind file
protected void btnOpenPop_Click(object sender, EventArgs e)
{
string url = "http://www.dotnetcurry.com";
ClientScript.RegisterStartupScript(this.GetType(), "OpenWin", "<script>openNewWin('" + url + "')</script>");
}
You can't use target attribute on button.
You have to use javascript function window.open()
Check this:
Window open() Method
I don't post links lightly, but I found this site explains all and it has solved my problem too.
http://dotnetspidor.blogspot.co.uk/2009/01/open-new-window-in-aspnet-web-page_28.html

Make a menu item behave like a button

Is it possible to make a menu item behave like a button? By this I mean that instead of setting the NavigateUrl property to a new page, assign a method when the item is clicked?
You can add a click handler for the menu.
The MenuItemClick tells you which item was clicked.
<asp:menu id="NavigationMenu"
onmenuitemclick="NavigationMenu_MenuItemClick"
runat="server">
You could take action depending upon which item was clicked by the user.
void NavigationMenu_MenuItemClick(Object sender, MenuEventArgs e)
{
if (e.Item.Text == "MyItem")
{
//do some processing
}
}
Ofcourse you can do it..you can call a server side function using__dopostback() for example
on your menu item's click you can call this Javascipt function
<script type="text/javascript">
function SaveWithParameter(parameter)
{
__doPostBack('btnSave ', parameter)
}
</script>
Try the below:
<asp:menuitem navigateurl="javascript:YourJScript()"
If you need to execute a method in serverside, use a hidden variable, then set a flag in javascript method and submit the page.
In serverside, check the flag in page load and call the method as required.
Thanks

2 onclick events on 1 Div ? (ASP.NET / HTML)

I'm using Div's, now I have to handle 2 Events with one Div-Click..
On the Button I would take, once onclick="" and OnClientClick.. but if I use a Div I can't use OnClientClick :(
Can you guys tell me, what I shall do, to get this? (there is one JavaScript method and one codebehind method, which I want to call) - till now I can call only one.
after wizards help:
got this:
<asp:Button ID="fakeButton" runat="server" Text="dummy" onclick="dummyButton_Click" style="display:none" />
and JS:
alert("div clicked");
document.getElementById("<%=fakeButton.ClientID%>").click();
So but he dont enters the Method:
protected void dummyButton_Click(object sender, EventArgs e) { } ..
i putted a breakpoint, he never entered, only showed the alert.. –
First, add dummy hidden button with the proper server side click event:
<asp:Button id="fakeButton" runat="server" OnClick="MyMethod" Text="dummy" style="display: none;" />
Second, have such code for the DIV:
<div onclick="DivClick();">text here...</div>
And finally such client side code:
function DivClick() {
//your client side code here...
//e.g.
alert("div clicked");
//now invoke server side click as well:
document.getElementById("<%=fakeButton.ClientID%>").click();
}
This will first execute your client side code e.g. the alert, then "auto click" the button and by this causing post back and the server side code to execute.
If you don't want full reload, try putting it all inside UpdatePanel.

I want to open a popup on clicking a button showing an aspx page

I have seen this in the West-Wind Toolkits where they have created their control called Hover Panel but i'm not able to implement it.So,is there another method to do so.
you can use jquery ui dialogs for this. Check out this sample
Have you had a look at the ModalPopupExtender as part of the ASP.NET AJAX Control toolkit?
ModalPopupExtender is an advanced option for pop up.
but if you want to do it simply you can use simple javascript to open popup form on button click :
Here is the script :
function popitup(url)
{
newwindow=window.open(url,'name','height=200,width=150');
if (window.focus) {newwindow.focus()}
return false;
}
add this in your html source for button click :
onclick="return popitup('test.aspx')"
In addition to Aarti's answer, you could open popup from asp.net code with Page's RegisterStartupScript function.
protected void Button1_Click(object sender, EventArgs e)
{
RegisterStartupScript("OpenPopup", "<script>popitup('PageToOpen.aspx');</script>");
}

Resources