I have a button,Linkbutton and an ModalPopup.
If I click button1 I need to click 2nd button automatically and Launch ModalPopup.But it's not triggering at all.
Can anyone say me where am I going wrong?
This is my ModalPopup:
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="LinkButton1"
PopupControlID="Panel1" BackgroundCssClass="modalBackground" DropShadow="False"
CancelControlID="CancelButton" />
<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none;
width: 300px;">
<asp:HyperLink ID="DownloadLink" runat="server" ForeColor="#0066FF">Download</asp:HyperLink>
<asp:Button ID="CancelButton" CssClass="btn-blue" runat="server" Text="Cancel" />
<asp:Button ID="button1" runat="server" Text="Select Image" Style="position: absolute;
left: 400px; top: 500px; z-index: 99;"/>
<asp:LinkButton ID="LinkButton1" OnClick="LinkButton1_Click" runat="server" Visible="true"
Style="position: absolute; left: 620px; top: 500px; z-index: 99;">Close</asp:LinkButton>
</asp:Panel>
<br />
</ContentTemplate>
</asp:UpdatePanel>
This is my code-behind:
1st Button:
Protected Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click
Linkbutton1_Click(Nothing,Nothing)
End Sub
2nd Button:
Protected Sub Linkbutton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Linkbutton1.Click
ModalPopupExtender1.Show
End Sub
Unless there's something I'm missing, the approach you're using seems unnecessarily complicated. Just create a method that opens the dialog, and you can call it anywhere...
protected void LinkButton1_Click(object sender, EventArgs e)
{
//perform whatever logic you need
//open the dialog
ShowDialog();
}
protected void Button1_Click(object sender, EventArgs e)
{
//perform whatever logic you need
//open the dialog
ShowDialog();
}
private void ShowDialog()
{
ModalPopupExtender1.Show();
}
Give this a try. For code within the first button click.
Linkbutton1_Click(sender, New System.EventArgs())
Related
I have file upload and label control in a repeater. The problem is whenever a file is uploaded, I want to assign name of the uploaded file to a label inside repeater.
<asp:Repeater ID="Repeater1" runat="server" ClientIDMode="AutoID">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text=""><img src="../images/upload.png" alt="" style="position:absolute;cursor:pointer;"/></asp:Label>
<asp:FileUpload ID="PhotoUpload" runat="server" CssClass="uplodfile" Style="padding: 0px; position: relative; left: 0px; top: 0px; width: 20px;" />
<asp:Label ID="lblFilePath" Text="" runat="server" Style="vertical-align: inherit; padding: 0px 5px;"></asp:Label>
</ItemTemplate>
</asp:Repeater>
Can anybody assist me how to achieve this?
You can use FindControl.
protected void PhotoUpload_Click(object sender, EventArgs e)
{
Label lbl = Repeater1.Items[0].FindControl("Label1") as Label;
lbl.Text = "Label found!";
}
i have a code ,where i want to change the lable text and visible mode in code behind file.my page is .ascx page
<asp:UpdatePanel ID="upnlTrvLogin" runat="server">
<ContentTemplate>
<div id="divErrMsg" runat="server" style="padding-left: 11px;">
<asp:Label ID="lblErrMsg" runat="server" ForeColor="Red" Visible="False"
CssClass="errorIcon" meta:resourcekey="lblErrMsgResource2"></asp:Label>
<br />
</div>
<div style="display: inline; float: right; text-align: right; margin-top: 10px; margin-right: 13px;">
<asp:Button ID="lnkSubmit" runat="server" CausesValidation="False"
CssClass="font1_2em bolder inButton showHand" OnClick="lnkSubmit_Click"
Text="Sign In" UseSubmitBehavior="False" meta:resourceKey="lnkSubmitResource2" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
code behind file
protected void lnkSubmit_Click(object sender, EventArgs e)
{
string User = GetUserDetail(txtUsername.Text.Trim(), txtPass.Text.Trim(),out personGuid, false);
if (string.IsNullOrEmptyUser (User )
{
lblErrMsg.Text = "Invalid email / password";
lblErrMsg.Visible = true;
return;
}
}
but in the button click event when i an try to change the Label text but is not changing . please tell why text of label is not changing.
Looking at you code, seems it is incorrect.
string.IsNullOrEmpty(User) was the correct statement, but you are using string.IsNullOrEmptyUser (User ).
Another tip, don't use variables with first letter on upper case, let it only for class.
So I'm trying to understand how this should be properly setup. I have a Updateprogress that shows a progress bar when a button is clicked. The button is wrapped in an UpdatePanel. But if there're any error, I want to stop the processing and then pop up a modal window (I used Modalpopupextender) to show the errors. My issue is, it just shows the box (or object) but without the texts that came from the Exception. Here's my code:
<asp:UpdatePanel ID="UpdatePanel_ActionButtons" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Approve" OnClick="Proccess_Click1" OnClientClick="this.disabled = true; this.value = 'Processing';" UseSubmitBehavior="false" />
</ContentTemplate>
</asp:UpdatePanel>
The Progress Bar:
<asp:UpdateProgress ID="UpdateProgress" runat="server" AssociatedUpdatePanelID="UpdatePanel_ActionButtons">
<ProgressTemplate>
<div style="background-color:Gray; filter:alpha(opacity=80); opacity:0.80; width: 100%; top: 0px; left: 0px; position: fixed; height: 800px;"></div>
<div style=" filter:alpha(opacity=100); position: fixed;
z-index: 100001;
left: 720px;
top: 105px;">
<div style="width:50px; height:50px; padding:50px; background-color:white; border:solid 1px black;">
<img alt="progress" src="../images/ajax-waiting.gif"/>
Processing...
</div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
The error box:
<asp:LinkButton ID="btnNotInUse" runat="server" />
<ajaxtoolkit:ModalPopupExtender ID="qaError" runat="server"
TargetControlID="btnNotInUse"
PopupControlID="pnlQAError"
BackgroundCssClass="modalPopupExtender" />
<asp:Panel ID="pnlQAError" runat="server" Style="display: none" CssClass="modalPopup">
<br />
<asp:Button ID="OkBtn" runat="server" Text="Ok" OnClick="OkBtn_Click" />
</asp:Panel>
Button Click Method:
protected void Proccess_Click1(object sender, EventArgs e)
{
List<string> validationErrors;
string returnurl;
Processrecord(out validationErrors);
if (validationErrors.Count() > 0)
{
foreach (var error in validationErrors)
{
qaFeedback.InnerHtml += error;
}
qaError.Show();
return;
}
else
{
returnurl = "toanotherpage.aspx";
}
}
So if you look as to how I add the errors, it's adding it to the "qafeedback" div. And then I would force it to show up and then return. What's happening is it would pop out the button box, with the button, but it doesn't show the texts I added. It would be helpful to know as well that when I remove the progress bar or animation, the whole thing works or shows the error messages.
Thoughts?
I have a Listbox with some items stored
and from a textbox's key up event i select my choice
the problem i am facing is that
once i select my choice Listbox1_selectIndexchanged event (which sets my choice to another textbox ) not firing properly, it fires only when i hit some button or some page postback event something...
[i have used JQuery and updatepanel]
Here is my Code
<%# Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Main.Master" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication2.WebForm1"
title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="uppnl" runat="server">
<ContentTemplate>
<script type="text/javascript" >
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function() {
$('select[id$=ListBox1]').filterByText($('input[id$=TextBox1]'), true);
});
</script>
<asp:Panel ID="Panel1" runat="server" Style="border-right: thin groove; border-top: thin groove; border-left: thin groove; border-bottom: thin groove; vertical-align: middle; width: 100%; text-align: center; padding-right: 5px; padding-left: 5px; padding-bottom: 5px; padding-top: 5px;">
<br />
<asp:Label ID="Label1" runat="server" Text="Type"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="SelectedText"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:ListBox ID="ListBox1" runat="server" Height="119px" Width="126px">
<asp:ListItem Text="Apple" Value="1"></asp:ListItem>
<asp:ListItem Text="Orange" Value="2"></asp:ListItem>
<asp:ListItem Text="Peache" Value="3"></asp:ListItem>
<asp:ListItem Text="Banana" Value="4"></asp:ListItem>
<asp:ListItem Text="Melon" Value="5"></asp:ListItem>
<asp:ListItem Text="Lemon" Value="6"></asp:ListItem>
<asp:ListItem Text="Pineapple" Value="7"></asp:ListItem>
<asp:ListItem Text="Pomegranate" Value="8"></asp:ListItem>
<asp:ListItem Text="Mulberry" Value="9"></asp:ListItem>
<asp:ListItem Text="Apricot" Value="10"></asp:ListItem>
<asp:ListItem Text="Cherry" Value="11"></asp:ListItem>
<asp:ListItem Text="Blackberry" Value="12"></asp:ListItem>
</asp:ListBox>
<asp:Button ID="Button1" runat="server" Text="Refresh" />
<br />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<script type="text/javascript">
jQuery.fn.filterByText = function(textbox, selectSingleMatch) {
return this.each(function() {
var select = this;
var options = [];
$(select).find('option').each(function() {
options.push({value: $(this).val(), text: $(this).text()});
});
$(select).data('options', options);
$(textbox).bind('change keyup', function() {
var options = $(select).empty().data('options');
var search = $.trim($(this).val());
var regex = new RegExp(search,"gi");
$.each(options, function(i) {
var option = options[i];
if(option.text.match(regex) !== null) {
$(select).append(
$('<option>').text(option.text).val(option.value)
);
}
});
if (selectSingleMatch === true && $(select).children().length === 1) {
$(select).children().get(0).selected = true;
}
});
});
};
$(function() {
$('select[id$=ListBox1]').filterByText($('input[id$=TextBox1]'), true);
});
</script>
</asp:Content>
and in my code behind i have
Protected Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ListBox1.SelectedIndexChanged
TextBox2.Text = ListBox1.SelectedItem.ToString()
End Sub
Your event did fire.
Control properties are loaded during the Page_Load method, and your event will fire after the Page_Load method so your page will not reflect its results. All events will fire after the Page_Load method as per the page life cycle.
Try this:
Protected Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ListBox1.SelectedIndexChanged
TextBox2.Text = ListBox1.SelectedItem.ToString()
Page_Load(sender, e)
End Sub
To learn more about the page life cycle check out http://msdn.microsoft.com/en-us/library/ms178472(v=vs.100).aspx
EDIT:
You also need to bind your listbox to your event:
<asp:ListBox ID="ListBox1" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged" runat="server">
I am trying to figure out why my ModalPopupExtender keeps closing, everytime a user clicks either button its running the code behind because I put a break point in and it is breaking there, but the modalPopup immediately closes, which isnt good because if it has any errors in the process they cant be displayed. So how do I stop the modalpopup from closing itself? I didnt specify a OKControlID or a CancelControlID.
Panel Code:
<asp:Panel ID="Panele" runat="server" style="display: none; position:absolute; top: 50%; left: 35%; width: 500px; height: 350px; background-color: White; border: solid 1px black; padding-left: 15px; text-align: left;">
<asp:ImageButton ID="CloseEBtn" runat="server"
ImageUrl="images/CloseButton.png" style="float: right; margin-right: 3px; margin-top: 3px;"
onclick="CloseEBtn_Click" />
<strong>Name:<asp:TextBox ID="fromTextBox" runat="server"></asp:TextBox></strong>
<asp:Button ID="SndBtn" runat="server" Text="Send" onclick="SndBtn_Click" />
<asp:Button ID="ClrBtn" runat="server" Text="Clear" />
<br />
<br />
<asp:Label ID="msglabel" runat="server"></asp:Label>
</asp:Panel>
My ModalPopupExtender Code:
<asp:ModalPopupExtender ID="popup" runat="server"
TargetControlID="SIBtn" PopupControlID="Panele" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>
CodeBehind:
protected void SndBtn_Click(object sender, EventArgs e)
{
msglabel.Text = "The Window Didnt Close";
}
protected void ClrBtn_Click(object sender, EventArgs e)
{
fromTextBox.Text = "";
toTextBox.Text = "";
subjectTextBox.Text = "";
MessageTextBox.Text = "";
msglabel.Text = "";
}
By code-behind running if you mean the page posts back, modal popups do not explicitly reload themselves. You have to write some code from the server to show the Modal Popup; there is a Server-side Show() method on the extender and a client-side show() method like:
$find("<%= mpe.ClientID %>").show();
HTH.
For me, UseSubmitBehavior="false" on the asp:Button did the trick.