There is a Visual WebPart being developed in SharePoint 2010. On load, a set of methods that get and fill information in the WebPart run in the Page_Load method. Somewhere in this process, there needs to be a popup message box or alert box notifying the user that this particular bit of information is not available.
The problem is doing the popup message. A MessageBox.Show will not work in this particular situation as it is a SharePoint Visual WebPart, which is an extenstion of ASP.NET. Adding System.Windows.Form is possible and it would make MessageBox.Show work, but only on the development machine. It will not work for any of the clients on their browsers. Adding the following to the ASP code is possible, but one of the objectives is to minimize user interaction.
<asp:Button ID="btnCheckInfo" runat="server" Style="z-index: 101; left: 216px; position: absolute;
top: 160px" Text="Check Information" OnClientClick="return confirm('change a record, would you like to continue ?');" />
Having this happen automatically instead of having the user click a button would be ideal.
Is this at all possible? Is it possible to add a popup message box of some kind to a SharePoint Visual WebPart that can be called/triggered within a method instead of as a click event?
Hopefully the question is clear enough. I'm not an experienced C#, .NET or SharePoint programmer.
Thank you in advance for you help and advice!
You can use the RegisterStartupScript to add some javascript to your page from anywhere you want (ie in the page_load method)
if(something)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "confirm", "change a record, would you like to continue ?');", true);
}
You would need to handle what happens when the user clicks OK
Related
I am using VS2015 with Windows10 and C#. My app has 4 options, all of which execute serially in the same window, displaying output in a gridview; some options also display a button that charts a selected row in a separate window.
Switching between options works fine, and the first time that I chart works fine. My problem is that when I close the chart window, run other options, then come back to one that charts, the button click fails. A window is displayed with the chart icon so OnClientClick appears to have run, but OnClick never executes and the chart is not filled.
I know no Java so do not know how to debug it. Can someone please suggest a fix or an alternative that does not use Java!
Here is the critical code in the button click.
<asp:Button
ID="GoChart"
CssClass="button"
runat="server"
Text="Select, then Chart"
Visible="false"
Style="border-radius: 0.4em; width: 9em; float: left; margin-left: 1px; color: white;"
ToolTip="Select a row in the grid, then click here to chart the row. "
OnClick="GoChart_Click1"
OnClientClick="window.open('NewChart.aspx','_blank');return false"/>
On the second use of the chart button, GoChart_Click1 is never reached.
Thanks for your help.
The function GoChart_Click1 should actually never be executed because in the OnClientClick you return false signaling the browser to not execute the default behaviour of the button which would be to call GoChart_Click1.
Remove the return false; so that GoChart_Click1 is executed.
However, I don't think this will solve your problem since I don't see how you could do something with the newly opened window from within GoChart_Click1.
I suppose you need to share the source of GoChart_Click1 and the source of NewChart.aspx to get a more detailed answer.
I suppose that whatever code you have in GoChart_Click1 that fills the chart would be better placed in the load event in NewChart.aspx.cs directly.
This
OnClientClick="window.open('NewChart.aspx','_blank');return false"
To
OnClientClick="window.open('NewChart.aspx','_blank');"
Return false will stop the service side Click of the button. If you want service side action to be executed after Client Click remove the return false part.
I have a TextBox and and I want to open a Popup on clicking TextBox. There is no Click event for TextBox. I want to do it in C# completely. I don't need jquery in opening Popup on Click of TextBox.
Asp.net textbox:
<asp:textbox onclick="myJavaScriptFunction()" runat="server" id="myTextBox" ... >
#edit
jquery example:
$("#target").click(function() {
alert("Handler for .click() called.");
});
The nature of creating a website solution like you are doing makes this impossible. In ASP.NET WebForms and MVC you do not deliver C# code to the user so you cannot create client side behavior with C#; instead, you deliver an HTML page and assets like files for Javascript, CSS, images, etc. If you want to invoke client side behavior, you need code that will run client side. That means using Javascript, and I recommend that you use jQuery while doing that.
nirmus's answer will give you an example for that, but to answer your question completely bluntly the answer is: "You can't."
I am new to the ASP.NET world and I need to do a popup to select some data.
The idea is that the user can select one or more options with a CheckBox. When he presses a button a popup appears with a list of options loaded from the database.
I don't know how to create a popup with those options and receive the selected options when the popup close. But I know how to do the option list from the database with a repeater.
there is no such popup control in ASP.NET.
However there are numerous 3rd party plugins, which provide popup controls.
ajax tool kit model popup extender
jquery built popups
you can create your own. popup is nothing but a hidden container, which appears upon some action, and whose location and background is as per your choice.
create a popup like this:
<div class="parent">
<div class="popup">
</div>
</div>
<input type="button" value="popup" id="btnpopup" />
and css
.parent
{
position:relative;
background-color:#CCCCCC;
width:200px;
height:200px;
}
.popup
{
width:50%;
height:50%;
position:relative;
top:20%;
left:20%;
background-color:#DDDDDD;
display:none;
}
and jQuery code
$('#btnpopup').click(function(){
$('.popup').toggle(200);
});
see this fiddle
You can use the OnClientClick of the button to open the popup. Depending on it being a normal browser popup or a jQuery dialog you have two general options:
Standard Popup
Standard popups open as if they are a separate page. When you click OK you may have to store the selection into the user's session if the data is needed on the page that triggered the popup, or store it directly in the database. If the former is the case, when you return to the page and submit it, the data from the popup will be available in the session to process.
jQuery Dialog or particularly any js-triggered html dialog. You can show it with the corresponding js again in the OnClientClick function, and perform the selection. On the OK button click of the dialog almost nothing is needed (except hiding it). Since the dialog input controls are part of the page, they will be posted on submit and be process-able on the server.
That's basically all you need to do, but some more reading on the topic won't hurt. Good luck.
What I’m trying to accomplish is this. I want it to be so that when the user clicks a button, a pop up comes up and allows them to complete, say, the survey. However, I do NOT want it to be a popup window, just something like in the image. Additionally, the pop up needs to be able to have a webpage embedded in it, because the survey is a page in itself. So basically, instead of it being that when the user clicks the button they are redirected, I want a pop up (not a popup window) to appear with the page in it. What I have used so far is iframe in a panel, but I feel there must be a better and more stable way, than using frames. Can anyone suggest a better method? Sorry about my terminology, if have no idea what this is called, I’m new to .ASP NET wed development.
Here is the code (the button changes visible=”False” to true):
<asp:Panel CssClass="BlowItUp" ID="Panel1" runat="server"
Visible="False" >
<iframe src="http://10.0.0.1/start.htm" style="width:100%; height:100%; top:0px;" />
</asp:Panel>
The CSS if it matters:
.BlowItUp
{
position:absolute;
width:80%;
height:90%;
z-index:300;
right:10%;
top:5%;
padding:0px;
}
Unless you have control over the "inner" page, I think a frame is the best you're going to manage. Otherwise the inner page will seek to navigate to another page and you'll lose your "framing".
The one thing I would suggest though is a different popup panel. Say jQuery UI Dialog?
I created an alert using MessageBox.Show method. But I'd like to forbid the editing of the controls in the page which is still accessible behind the messagebox. If I try to disable every control manually before firing the messagebox the controls are disabled only after picking a choice in the messagebox.
Please Help :)
Ok, I found a way to do what I need.
You can add an "onclientclick" event to the button you want to fire the Confirm Popup.
<asp:Button id="Button" runat="server" onclientclick="return confirm('Are you sure?');"
onClick="ServerSideMethod_Button_Click" />
If you answer OK to the popup server-side method will be executed, otherwise it will be skipped.
Thank you all for the help. :)
It is a client-side solution you'll need. Given you want to both pop-up a message and disable the GUI/page underneath I'd recommend you take a look at modal dialogs. JQuery has provides de facto industry standard box, but others are available. Just Google it.