FileUpload inside jquery dialog, hasfile false - c#

I have a jquery UI dialog on my page. It contains nothing more than a single asp FileUpload control:
<asp:FileUpload runat="server" ID="fuAttachment" />
The dialog has 1 button "OK". Those button simply closes the dialog
$("#attachment-dialog").dialog({
height: 300,
width: 400,
modal: true,
resizable: false,
autoOpen: false,
buttons: {
"OK": function () {
$(this).dialog("close");
}
}
});
When pressing the save button on my page. Which is an asp.net button the method SaveAttachement is called.
The problem is that fuAttachment.HasFile (the fileupload control) keeps returning false.
If I move the fileupload control outside of the jQuery UI dialog. HasFile = true.
But the control should be inside the dialog. There's no updatepanel inside the specific page.

The problem is happening because the dialog is outside of the form.
jQuery UI Dialog has an appendTo parameter that will ensure the dialog is part of the form.
$("#attachment-dialog").dialog({
appendTo: "form",
height: 300,
width: 400,
modal: true,
resizable: false,
autoOpen: false,
buttons: {
"OK": function () {
$(this).dialog("close");
}
}
});

Related

No postback after user confrim in jquery dialog box

I am newsiest on jQuery. I need to show the dialog box to get the user response. If the use click confirm, I need to update the database on sever. I found the example jQuery dialog Confirm-JSFiddle and followed the code. However, after the user click confirm, it is not postback to server. Would someone tell me how to fix it.
There is my jQuery script code:
$(document).ready(function() {
$("#dialog-confirm").dialog({
autoOpen: false,
modal: true
});
});
$(function() {
$("#dialog-confirm").dialog({
autoOpen: false,
modal: true,
buttons : {
"Confirm" : function() {
$(this).dialog("close");
return true;
},
"Cancel" : function() {
$(this).dialog("close");
return false;
}
}
});
$("#Button1").on("click", function(e) {
e.preventDefault();
$("#dialog-confirm").dialog("open");
});
});
There is the code on vb.net
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim i As Integer = 0
End Sub
There is the button on aspx page
<asp:button id="Button1" runat="server" text="test" visible="true" />
You're just need one step to do postback by using appendTo function to bind with target form:
$("#Button1").on("click", function(e) {
e.preventDefault();
$("#dialog-confirm").dialog("open");
$("#dialog-confirm").parent().appendTo($("form:first"));
});
<asp:Button id="Button1" runat="server" text="test" visible="true" OnClick="Button1_Click" />
Of course, if you're using dynamic client ID (without ClientIDMode="Static" attribute at asp:Button), you need to use ClientID instead of button's server ID:
$("#<%= Button1.ClientID %>").on("click", function(e) {
e.preventDefault();
$("#dialog-confirm").dialog("open");
$("#dialog-confirm").parent().appendTo($("form:first"));
});
Or you can embed appendTo into dialog setting (with jQuery 1.10 and above):
$("#dialog-confirm").dialog({
autoOpen: false,
modal: true,
buttons : {
"Confirm" : function() {
$(this).dialog("close");
return true;
},
"Cancel" : function() {
$(this).dialog("close");
return false;
}
},
appendTo: "form" // append this setting
});
If appendTo doesn't work with your page, try __doPostBack method (but not guaranteed to work with all browsers):
__doPostBack('<%= Button1.UniqueID %>', '');
Similar issues:
jQuery UI Dialog with ASP.NET button postback
jQuery modal form dialog postback problems

Popup window get value and clear while close it

I have alert pop up window on dblclick of textbox. I have a text area inside pop up window, I want to store the value entered in popup window in temporary variable and close popup window. Is it possible to store the data temporary and also clear the data once popup window is closed by user. because for multiple textboxes have same alert window.
var opt = {
autoOpen: false,
modal: true,
width: 350,
height: 'auto',
title: 'Comments'
};
$(function () {
$("#Cmnts").dialog({
autoOpen: false
});
});
$(document).ready(function () {
var theDialog = $("#Cmnts").dialog(opt);
$("input[type='text']").on("dblclick", function () {
$('#Cmnts').dialog('open');
});
});
<div id="Cmnts" style="display:none;">
<textarea name="Cmnts" id="CmntsTxt" rows="5" cols="30"></textarea>
</div>
can anyone help me to solve this
Thanks in advance..
Add the below code in ready
$("#Cmnts").on('dialogclose', function(event) {
$("#dialogValue").val($('#CmntsTxt').val())
$('#CmntsTxt').val('');
});
Add HTML
<input type="hidden" id="dialogValue">
Here is the demo

Asp:Button - if OnClientClick = True | False

<asp:Button ID="Invoice" runat="server" Text="Create Invoice" OnClientClick="CreateInvoice_Click()" OnClick="CreateInvoice_Click1"/>
<script type="text/javascript" language="javascript">
function Create_Invoice() {
$("#dialog-confirm").dialog({
resizable: false,
height: 180,
modal: true,
buttons: {
Create: function () {
$(this).dialog("close");
},
Cancel: function () {
//code needed here
$(this).dialog("close");
}
}
});
}
</script>
<p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>Are you sure?</p>
So user presses the 'Create Invoice' button, pop up appears allowing the user to select 'Create' or 'Cancel'.
The 'CreateInvoice_Click' function is run on code behind if the user clicks 'create' or 'cancel'. What I want to know (which needs to go inside the 'cancel' function') how do I say ignore the OnClick="CreateInvoice_Click1" if cancelled is clicked.?
Thanks for any replies
if you want to prevent the server side function from execution you simply need to return false in your client side function.
function Create_Invoice() {
$("#dialog-confirm").dialog({
resizable: false,
height: 180,
modal: true,
buttons: {
Create: function () {
$(this).dialog("close");
},
Cancel: function () {
//code needed here
$(this).dialog("close");
return false;// that's all what you need
}
}
});
}
Seems like you are tryign to recreate something javascript does with a built in function.
function confirmation() {
var answer = confirm("Leave tizag.com?")
if (answer){
alert("Bye bye!")
window.location = "http://www.google.com/";
}
else{
alert("Thanks for sticking around!")
}
}
Taken from http://www.tizag.com/javascriptT/javascriptconfirm.php
you should try manually calling the serverside click event by using javascript;
checkout the code inside Create and Cancel button;
<script type="text/javascript">
$('#test').on('click', function(e){
e.preventDefault();
$("#dialog-confirm").dialog({
resizable: false,
height: 180,
modal: true,
buttons: {
Create: function () {
$(this).dialog("close");
// manually calling serverside click event
$('#buttonHidden').click();
},
Cancel: function () {
//code needed here
$(this).dialog("close");
// don't call it manually here and thus it won't fire the serverside click event
}
}
});
});
</script>
// your button here to call javascript
<button id="test" runat="server">Create Invoice</button>
// the hidden button just to hold the CreateInvoice_Click1 which is fired from fireClick()
<asp:Button ID="buttonHidden" runat="server" Style="display: none" OnClick="CreateInvoice_Click1" />
your code behind;
protected void CreateInvoice_Click1(Object sender, EventArgs e)
{
//your server side code
}
<asp:Button ID="Invoice" runat="server" Text="Create Invoice" OnClientClick="return Create_Invoice()" OnClick="CreateInvoice_Click1"/>
<script type="text/javascript" language="javascript">
function Create_Invoice() {
$("#dialog-confirm").dialog({
resizable: false,
height: 180,
modal: true,
buttons: {
Create: function () {
$(this).dialog("close");
return true;
},
Cancel: function () {
//code needed here
$(this).dialog("close");
return false;
}
}
});
}
<p id="dialog-confirm"><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>Are you sure?</p>
your code behind;
protected void CreateInvoice_Click1(Object sender, EventArgs e)
{
//your server side code
}

How to select the value of a link button in gridview

I have a gridview i am trying to select the value of a link button clicked on a specific row of gridview. below is my code and it is erroring out due to the improper selecting of link button in gridview. Please help me in figuring this out.
on page load this is the error
ASP.Test_aspx does not contain a definition for 'lnkview' and no
extension method 'lnkview' accepting a first argument of type
'ASP.createsegment_aspx' could be found (are you missing a using
directive or an assembly reference?)
function:
$(document).ready(function() {
if($('#<%=this.lnkview.ClientID %>').length){
$('#this.lnkview').click(function(event) {
event.preventDefault();
$('#plnClone').dialog({
modal: true,
width: 550,
height: 250,
open: function(type, data) {
$(this).parent().appendTo("form");
}
});
});
}
$('#CancelClone').click(function(event) {
event.preventDefault();
$('#plnClone').dialog('close');
});
//
if ($('#hfdCloneOffer').val() == "DUPLICATE") {
$('#plnClone').dialog({
modal: true,
width: 550,
height: 250,
open: function(type, data) {
$(this).parent().appendTo("form");
}
});
//
// Scroll to Page Top
$('html, body').animate({ scrollTop: '0px' }, 800);
}
The second line of your code appears to be missing the server tags.
$('#this.lnkview')
Should become
$('#<%=this.lnkview.ClientID %>')
EDIT
Looking at your markup, I don't think you'll be able to do a lnkView.ClientID on it outside of the grid row. Suggest you use put a class on your linkbutton and use it as a selector instead.
MORE EDIT
Something like this should work
<asp:LinkButton ID="lnkView" runat="server" Text="View" CausesValidation="false" CssClass="lnkViewClass">
$('.lnkViewClass').click(function(event) {
event.preventDefault();
$('#plnClone').dialog({
modal: true,
width: 550,
height: 250,
open: function(type, data) {
$(this).parent().appendTo("form");
}
});
});
}
Are you sure that you have element with id 'lnkview' in your aspx code? You are calling this here '#<%=this.lnkview.ClientID %>'

How to refresh a parent page after closing sharepoint dialog?

How to refresh a parent page after closing sharepoint dialog?
Here is my coding to open a pop-up.
<input type="button" value="Add" class="button submit" style="width: 80px" onclick="javascript:OpenAttachmentUpload()" />
<script type="text/javascript">
//User Defined Function to Open Dialog Framework
function OpenAttachmentUpload() {
var strPageURL = '<%= ResolveClientUrl("~/Dialogs/AttachUpload.aspx") %>';
//OpenFixCustomDialog(strPageURL, "Attachment");
OpenCustomDialog(strPageURL, 350, 200, "Attachment");
return false;
}
</script>
here is the script.
function OpenCustomDialog(dialogUrl, dialogWidth, dialogHeight, dialogTitle, dialogAllowMaximize, dialogShowClose) {
var options = {
url: dialogUrl,
allowMaximize: dialogAllowMaximize,
showClose: dialogShowClose,
width: dialogWidth,
height: dialogHeight,
title: dialogTitle,
dialogReturnValueCallback: Function.createDelegate(null, CloseCallback3)
};
SP.UI.ModalDialog.showModalDialog(options);
}
After opening it, when I close the pop-up (~/Dialogs/AttachUpload.aspx) , I wanna refresh the parent page.
How can I do it?
I google and see SP.UI.ModalDialog.RefreshPage but still can't find an answer for me.
Thanks.
P.s
I don't know much about SharePoint.
You're almost there.
In the option dialogReturnValueCallback you can define a function that will be executed after the dialog was closed. By now you create a delegate pointing to CloseCallback3 but this is not defined in your code.
If you call SP.UI.ModalDialog.RefreshPage in this callback method the page gets refreshed after the dialog was closed with OK.
var options =
{
url: dialogUrl,
allowMaximize: dialogAllowMaximize,
showClose: dialogShowClose,
width: dialogWidth,
height: dialogHeight,
title: dialogTitle,
dialogReturnValueCallback: function(dialogResult)
{
SP.UI.ModalDialog.RefreshPage(dialogResult)
}
}
Btw:
You use javascript: in the onclick of the button. This is not necessary. this is only required in the href of an a tag
You can also use the build-in function "RefreshOnDialogClose"
SP.UI.ModalDialog.showModalDialog({
url: dialogUrl,
allowMaximize: dialogAllowMaximize,
showClose: dialogShowClose,
width: dialogWidth,
height: dialogHeight,
title: dialogTitle,
dialogReturnValueCallback: RefreshOnDialogClose
});
Try to use this code on click of a button:
<script type="text/javascript">
function RefreshParent()
{
SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.Ok, null);
}
</script>
If you only want to refresh the page if changes were made you can use the following call back instead.
var options =
{
url: dialogUrl,
allowMaximize: dialogAllowMaximize,
showClose: dialogShowClose,
width: dialogWidth,
height: dialogHeight,
title: dialogTitle,
dialogReturnValueCallback: function(dialogResult)
{
if (dialogResult != SP.UI.DialogResult.cancel)
{
SP.UI.ModalDialog.RefreshPage(dialogResult)
}
}
}
Saves you from refreshing the page if the user hit cancel.
Try java-script code as below in Closecall back.
window.location = window.location;

Categories

Resources