I am having an empty div and i am using LOAD method of jquery and getting data from another aspx page. it works fine. it gets File upload and button control from that page. now when i click on the button my button code doesn't get called and my dialog gets close.
jQuery On Page1.aspx
var checkP = $('#<%= productName.ClientID %>').val();
checkP = checkP.replace(/\ /g, '-');
$("#midDiv").load("UploadImages.aspx?prodName=" + checkP + " #midDiv");
$("#midDiv").dialog();
//It Shows Dialog With File Upload Option & Button Option.
Page1.aspx
<div id="midDiv">
</div>
Page2.aspx
<div id="midDiv">
<asp:FileUpload ID="productsImages" CssClass="hid" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="uploadImageTemp" Text="Button" />
</div>
Page2.aspx.cs //Code Behind
protected void uploadImageTemp(object sender, EventArgs e)
{
//Some Work Here...
}
Is there any way that my button code gets called or is there any way to keep jQuery modal open ?
Append your dialog in form like below.
var checkP = $('#<%= productName.ClientID %>').val();
checkP = checkP.replace(/\ /g, '-');
$("#midDiv").load("UploadImages.aspx?prodName=" + checkP + " #midDiv");
$("#midDiv").dialog().parent().appendTo($("form:first"));
Change your button control to link button control.
<div id="midDiv">
<asp:FileUpload ID="productsImages" CssClass="hid" runat="server" />
<asp:LinkButton ID="Button1" runat="server" OnClick="uploadImageTemp" Text="Button" />
</div>
Now call your code behind button click event.
Related
I have a button in my gridview and when the users click on it, it goes to the page. However, if you right click on it and "open link in a new tab" it goes to a blank page. I want it so when the user right click on it and "open link in a new tab" to go to the page. This is the code that I have so far:
aspx
<asp:LinkButton ID="lnkEditbtn" data-toggle="tooltip" title="View Request" OnClick="lnkEditbtn_Click" runat="server" class="btn btn-primary btn-sm" Text="<%# bind('ticketID')%>"></asp:LinkButton>
c#
protected void lnkEditbtn_Click(object sender, EventArgs e)
{
GridViewRow gvr = (GridViewRow)(((Control)sender).NamingContainer);
Label lblid = (Label)gvr.FindControl("lblMovie");
int id = Convert.ToInt32(lblid.Text.ToString());
SecureQueryString qs = new SecureQueryString();
qs["ID"] = id.ToString();
Response.Redirect("viewMovie.aspx?qs=" + qs.ToString());
}
you cannot do this with linkbutton because it redirects to the desired view after you click on it but you can use asp:HyperLink and set its value like
<asp:HyperLink ID="lnkEditbtn" data-toggle="tooltip" Text="View Request" runat="server" NavigateUrl='<%# Eval("ticketID", "~/viewMovie.aspx?qs={0}") %>' class="btn btn-primary btn-sm" ></asp:HyperLink >
Edit
if you want the URL to be encrypted first create a class
public static class encrypt
{
public static string encvalue(int id)
{
SecureQueryString qs = new SecureQueryString();
qs["ID"] = id.ToString();
return qs.ToString()
}
}
and your hyperlink will be
<asp:HyperLink ID="lnkEditbtn" data-toggle="tooltip" Text="View Request" runat="server" NavigateUrl='<%# String.Format("~/viewMovie.aspx?qs={0}",encrypt.encvalue(Convert.ToInt32(Eval("ticketID")))) %>' class="btn btn-primary btn-sm" ></asp:HyperLink >
Link button in server side gets rendered to Hyperlink in client side with 'href' as href="javascript:__doPostBack('lnkEditbtn',''), which is nothing but a postback to the server from the link button. So when you right click and open the link in a new tab, it posts to the server and hence it comes up as blank page in new tab.
What you can do is use code similar to the below code:
<style>
.hide {
display:none;
}
</style>
<script>
function postBack() {
__doPostBack('lnkEditbtn', '');
return false;
}
</script>
<asp:LinkButton ID="lnkEditbtn" runat="server" OnClick="lnkEditbtn_Click" Text="Link" CssClass="hide"></asp:LinkButton>
Link
protected void lnkEditbtn_Click(object sender, EventArgs e)
{
var linkButton = (Control)sender as LinkButton;
}
With this code, you are hiding the link button and using the Anchor tag instead.
Href in Anchor tag will be invoked when you right click. And when you click the link, "postBack" JS method will be triggered that invokes the server side event handler for the Link Button.
And there by both right click and left click works.
I'm using bootstrap carousel slideshow, and it's dynamically created from code behind. I want to add a button (Delete) to delete the current displayed image in the slide show.
The problem is that when I want to access the Html Image Source (Src) from the SlideShow, it will not accessed(It's empty).
My code looks like this:
Default.aspx
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<triggers>
<asp:PostBackTrigger ControlID="btnDeleteImage" />
</triggers>
<ContentTemplate>
<div class="text-right">
<asp:Button ID="btnDeleteImage" runat="server" Text="X" OnClick="btnDeleteImage_Click"/>
</div>
-
-
-
<!-- Div for Slide images -->
<div class="carousel-inner" id="sliderDiv" runat="server"> </div>
-
-
-
</div>
</ContentTemplate>
</asp:UpdatePanel>
The html controls are dynamically added to the div as shown below:
Default.aspx.cs
protected void CreateSlider(string imgUrl)
{
sliderDiv.Controls.Add(new LiteralControl(#"<div class='item'>"));
sliderDiv.Controls.Add(new LiteralControl(#"<img alt='image' id='imgSlide' src='" + imgUrl + "'>"));
sliderDiv.Controls.Add(new LiteralControl(#"</div>"));
}
Finnally, ButtonDelete code:
protected void btnDeleteImage_Click(object sender, EventArgs e)
{
HtmlImage htmlImage = (HtmlImage)sliderDiv.FindControl("imgSlide");
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", "<script>alert('" + htmlImage.Src.ToString() + "');</script>", false);
DeleteImagesFromTemp(htmlImage.Src.ToString());
}
By the way, I also added the postback code in the page Load event.
Any suggestions?
I have 2 cascading dropdownlists and a button. I placed all the 3 controls within an asp.net update panel.I do not want to do a full postback. The problem now is that , my button click event contains a "windows.open function" and this no longer opens a new window because my button is within an update panel I guess. I would like to know how I can get the url to open in a new window again ? (It doesn't have to be a windows.open function, but I would like to open the url www.google.com in a new window or tab. I do not want to use Response.redirect)
Please let me know.
Markup :
<asp:UpdatePanel ID="UP" runat="server" >
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Label Text="Team :" runat="server"></asp:Label>
<asp:DropDownList ID="ddlProject" OnSelectedIndexChanged="itemSelected" AutoPostBack="True" runat="server"></asp:DropDownList>
<br />
<asp:Label Text="Project :" runat="server"></asp:Label>
<asp:DropDownList ID="ddlDetails" runat="server"></asp:DropDownList>
<br/>
<asp:Button ID="btnSubmit" class="btn btn-primary"
Text="Submit" OnClick="btnSubmit_Click" runat="server"/>
</ContentTemplate>
</asp:UpdatePanel>
Code :
protected void btnBugSubmit_Click(object sender, EventArgs e)
{
//Code simplified below
string m = "Https://www.google.com";
string s = "window.open('" + m + "', 'popup_window', 'width=300,height=100,left=100,top=100,resizable=yes');";
ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
}
I also tried using
ScriptManager.RegisterStartupScript(this,this.GetType(), "script",s, true);
instead of
ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
but this also opens the url in the same window. I would like to open url in a new window or tab.
i want to show gridview in bootstrap modal popup on button click but until gridview not getting bind i just want to show loading panel and for that what i am doing is..
i am calling loading popup as from button click as below.
<asp:Button ID="btnSearch" runat="server" CausesValidation="true" Text="Search" CssClass="btn btn-info pull-right"
OnClientClick="waitingDialog.show();" ValidationGroup="MinMax" OnClick="btnSearch_Click" />
Meanwhile In codebehind i am calling Button OnClick And There After GridView bind I am Doing below process.
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(#"<script type='text/javascript'>");
sb.Append("$('#myModal').modal('show');");
sb.Append("waitingDialog.hide();");
sb.Append(#"</script>");
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "MinMax Data Report", sb.ToString(), false);
But The Problem is My GridView Is Very Big But When the popup with gridview getting Load It Not Showing horizontal and Vertical Scrollbar. In other word popup just load without scrollbar. And If I remove loading Panel and Calling direct That PopUp then It Working Fine. i am just not getting anything.
i want loading panel because my gridview takes nearly 32 seconds to load.
below is my gridview modal body.
<div class="modal-body" style="width=97%; overflow: auto;">
<div class="tabel-responsive">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Panel ID="panel2" runat="server" ScrollBars="Auto" Width="100%" Height="100%"
HorizontalAlign="Center">
<asp:GridView ID="gvMeterData" runat="server" RowStyle-Wrap="false" CssClass="table table-striped"
GridLines="Both" OnRowDataBound="gvMeterData_RowDataBound" HeaderStyle-HorizontalAlign="Center">
</asp:GridView>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gvMeterData" EventName="RowDataBound" />
<asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</div>
My Loading Popup is as below.
var waitingDialog = waitingDialog || (function ($) {
'use strict';
// Creating modal dialog's DOM
var $dialog = $(
'<div class="modal fade" data-backdrop="static" data-keyboard="false" tabindex="-1" role="dialog" aria-hidden="true" style="padding-top:15%; overflow-y:auto;">' +
'<div class="modal-dialog modal-sm">' +
'<div class="modal-content">' +
'<div class="modal-header"><h3 style="margin:0;"></h3></div>' +
'<div class="modal-body">' +
'<div class="progress progress-striped active" style="margin-bottom:0;"><div class="progress-bar" style="width: 100%"></div></div>' +
'</div>' +
'</div></div></div>');
return {
/**
* Opens our dialog
* #param message Custom message
* #param options Custom options:
* options.dialogSize - bootstrap postfix for dialog size, e.g. "sm", "m";
* options.progressType - bootstrap postfix for progress bar type, e.g. "success", "warning".
*/
show: function (message, options) {
// Assigning defaults
if (typeof options === 'undefined') {
options = {};
}
if (typeof message === 'undefined') {
message = 'Loading';
}
var settings = $.extend({
dialogSize: 'm',
progressType: '',
onHide: null // This callback runs after the dialog was hidden
}, options);
// Configuring dialog
$dialog.find('.modal-dialog').attr('class', 'modal-dialog').addClass('modal-' + settings.dialogSize);
$dialog.find('.progress-bar').attr('class', 'progress-bar');
if (settings.progressType) {
$dialog.find('.progress-bar').addClass('progress-bar-' + settings.progressType);
}
$dialog.find('h3').text(message);
// Adding callbacks
if (typeof settings.onHide === 'function') {
$dialog.off('hidden.bs.modal').on('hidden.bs.modal', function (e) {
settings.onHide.call($dialog);
});
}
// Opening dialog
$dialog.modal();
},
/**
* Closes dialog
*/
hide: function () {
$dialog.modal('hide');
}
};})(jQuery);
Edited: I think there might be problem with update panel. isn't that? but without update panel also i can not tracking the error. and again when i look in inspect element in browser than there also no error in console such as missing .js or anything.
Thanks In Advance.
I could not figure out that where should be the mistake in my code as above and i can not use AJAX for this because it is not supported in Yocto OS as i have to make this code run in there.
so at last i have make changes in my solution as below and i found the way to show loading..
There Are 2 ways i found..
1 is in this link.. Loading In Popup..
Another Way Is I kept Timer And Load 'Loading Image' In Start of page and Stop That Loading Image when my gridview bind fully by disabling timer. That Logic is as below.
.aspx Page..
<asp:Timer ID="Timer1" runat="server" OnTick="TimerTick" Interval="6000">
</asp:Timer><asp:Image ID="imgLoader" runat="server" ImageUrl="~/loading7.gif" />
.CS page
protected void TimerTick(object sender, EventArgs e)
{
this.fillGrid();
Timer1.Enabled = false;
imgLoader.Visible = false;
}
This Works Good.
But Still I am Waiting For Answer of My Actual Question. That Why Scroll Goes Out or Not Working.
hi I have one parent page which opens a pop up window, and user makes some changes on child pop up page then clicks a save button.
When the user clicks the save button, I want to doPostBack to the parent page so that the changes made in the pop up window can be seen in parent window.
Question : How can I achive the above scenario?
I want to write the script code in aspx.cs file, I tried
string script = "";
script = "<script>window.opener.__doPostBack('UpdatePanel1', '')</script>";
ScriptManager.RegisterClientScriptBlock(Literal1, typeof(Literal), "yenile", script, true);
but this did not do anything, no errors just nothing.
I am new to JavaScript, need help with all steps.
The parent page:
<asp:UpdatePanel runat="server">
<ContentTemplate>
<div>
<asp:Literal runat="server" ID="ChildWindowResult" />
</div>
<hr />
<input type="button" value="Open Dialog" onclick="window.open('MyDialog.aspx', 'Dialog');" />
<asp:Button ID="HiddenButtonForChildPostback" runat="server"
OnClick="OnChildPostbackOccured" style="display: none;" />
<asp:HiddenField runat="server" ID="PopupWindowResult"/>
</ContentTemplate>
</asp:UpdatePanel>
The MyDialog page:
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
function postData() {
var resultField = $("input[type='hidden'][id$='PopupWindowResult']", window.opener.document);
var parentPosDataButton = $("[id$='HiddenButtonForChildPostback']", window.opener.document);
resultField.val($("#<%= SomeValueHiddenField.ClientID %>").val());
parentPosDataButton.click();
}
</script>
<asp:TextBox runat="server" ID="SomeValueHiddenField" />
<asp:Button runat="server" OnClick="PostData" Text="Click Me" />
protected void PostData(object sender, EventArgs e)
{
SomeValueHiddenField.Value = DateTime.Now.ToString();
ClientScript.RegisterStartupScript(this.GetType(), "PostData", "postData();", true);
}
But I believe that it would be much better to utilize here some pop-up controls like PopUpExtender from the AjaxControlToolkit library or dialog from the jQuery-UI.
You probably need to use ClientID:
string script = "";
script = "<script>window.opener.__doPostBack('" + UpdatePanel1.ClientID + "', '')</script>";
ScriptManager.RegisterClientScriptBlock(Literal1, typeof(Literal), "yenile", script, true);
The last parameter is to whether include script tag or not
So, if you do
RegisterClientScriptBlock(page,type, "<script>foo();</script>", true);
You will end up with:
"<script><script>foo();</script></script>"
So, change your last parameter to false, or better yet, remove the tags in the string
Review the following suggested solution:
http://livshitz.wordpress.com/2011/06/12/use-popup-to-postbackupdate-its-parentopener-without-losing-viewstate-values-and-close/#more-16