How to select the value of a link button in gridview - c#

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 %>'

Related

Access a button on modal page

I've got a page that opens a modal (Page1.aspx).
That modal is another aspx page (Page2.aspx).
How can I declare in the opener page (or any other way), that a modal button, executes a button click in Page2.aspx.
I've tried to put:$('#ButtonOK').click(); (as it's the buttons id), but on the parent page it isn't recognized.
How can I execute that click?
Many thanks.
MY CODE, PAGE1:
function createModal(f,w,h) {
var dialogWidth = w;
var dialogHeight = h;
$('#dialog').dialog({
autoOpen: false
, bigframe: false
, modal: true
, width: dialogWidth
, height: dialogHeight
, autoResize: true
, closeOnEscape: true
, position: { my: "center", at: "center", of: window.top }
, open: function (event, ui) {
$('#dialog').css('overflow', 'hidden'); //this line does the actual hiding
}
,buttons: {
Ok: function () {
$("input[id$='ButtonOK']").trigger('click');
},
Cancelar: function () {
$(this).dialog("close");
}
}
});
$('#dialog').dialog('open');
$("#iframe").attr('src', f);
return false;
}
function PermMV(usr) {
createModal('new.aspx?usr=' + usr,350,450);
}
<div id="dialog" style="display: none;">
<iframe id="iframe" width="100%" height="100%" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" align="middle"></iframe>
</div>
PAGE 2:
<div id="acrescenta2" title="Perm">
<asp:TextBox ID="txtuser1" name="txtuser" runat="server" Text="" CssClass="consprodtxt" />
<asp:Button ID="ButtonOK" runat="server" OnClick="ButtonOK_Click" OnClientClick="ButtonOK_Click" Text="OK" CssClass="btnmv" />
</div>
Hope that helps.
You need to use IFrame Like This,
<div class="modal-body" id="modal_dialog">
<iframe style=" width:100%; height: 100%;" id="ifrm" src="yourExternalPage.aspx" runat="server">
</iframe>
And Open This Div as a Dialogue using JQuery,
<script type="text/javascript">
$("#BtnClick").live("click", function () {
$("#modal_dialog").dialog({
title: "jQuery Modal Dialog Popup",
buttons: {
Close: function () {
$(this).dialog('close');
}
},
modal: true
});
return false;
});
</script>
1<>Simple jQuery Modal Popup Window Example in ASP.Net
2<>Modal popup using jquery in asp.net
$(document).on("click","element",function(args){
//...
});
Try it
Try this:
$("#ButtonOK").trigger('click');

FileUpload inside jquery dialog, hasfile false

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");
}
}
});

How can I use a c# variable in jquery?

I have a project that I am going to call image paths from SQL. I have tested placing the variable in the image source
HTML
<li><a href='"<%=img_src_path%>"'><img src='"<%=img_src_path%>"' id="myImage" runat="server" alt="" title=""/></a></li>
Code Behind
myImage.src = "imagePage";
Is this same thing possible with javascript? here is my jquery:
$("#fancybox-manual-c").click(function () {
$.fancybox.open([
{
href: '1_b.jpg',
title: 'My title'
}, {
href: '2_b.jpg',
title: '2nd title'
}, {
href: '3_b.jpg'
}
], {
helpers: {
thumbs: {
width: 75,
height: 50
}
}
});
Is it now possible to put the value of myImage in place of the actual images listed here in the jQuery
Yes, you can use <%= %> syntax in JavaScript to inject server variables into your code:
$("#fancybox-manual-c").click(function () {
$.fancybox.open([
{
href: '<%= img_src_path_1 >',
title: 'My title'
}, {
href: '<%= img_src_path_2 >',
title: '2nd title'
}, {
href: '<%= img_src_path_3 >'
}
], {
helpers: {
thumbs: {
width: 75,
height: 50
}
}
});
});
You could also access the src property of any image on your page with jQuery:
$("#myImage").prop("src");
But, there is some weirdness in your code:
You are setting the img src twice. Once with <%= %> in the HTML and again in the code behind with myImage.src = "imagePath";. Why?
You are double quoting your HTML attributes. Use single quotes or double quotes, but not both on a single attribute.
I'm not familiar with fancybox, but this is how I would use jQuery to do the basic idea.
$(document).ready(function() {
img_path = "/the_new_img_path.jpg"
$("#img_link").attr("href", img_path)
$("#img").attr("src", img_path)
})
Then in the HTML
<a href='/some_default_link' id='img_link'><img id='my_img' src='/some_default_image.jpg' /></a>

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 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