modal popup extender button event using c# - c#

I have written modalpopupextender and it is successfully displaying. My problem is after enter the text in modalpopup i will click on save button but it is not working, after clicking the button popup will close and data will not store in my database following are the aspx code
<asp:Button ID="freeservice" runat="server" CssClass="hidden" />
<asp:ModalPopupExtender ID="ModalPopupExtender" runat="server" BehaviorID="mpe" PopupControlID="panel" TargetControlID="freeservice" OkControlID="savetxt" BackgroundCssClass="modalBackground" CancelControlID="cancel"></asp:ModalPopupExtender>
<asp:Panel ID="panel" runat="server" CssClass="modalPopup" Style="display: none;">
<asp:Button ID="cancel" runat="server" Text="X" CssClass="modalDialog" />
<div class="Popup_header">
Free service
</div>
<div class="modalbody">
<h3>Do you want to get free text update on your mobile when IRS takes decision on your
form?
<br />
If yes, please enter mobile number on which you want to get update:</h3>
<table>
<tr>
<td>Mobile Number</td>
<td style="width: 1px">
<asp:TextBox ID="txtmobile" runat="server" CssClass="divtxt"></asp:TextBox>
<asp:RegularExpressionValidator ID="revmobile" runat="server" SetFocusOnError="true"
Display="None" ErrorMessage="Mobile number must be of 10 digits" ControlToValidate="txtmobile"
ValidationExpression="[0-9]{10}"></asp:RegularExpressionValidator>
<asp:ValidatorCalloutExtender ID="vce_revmobile" runat="server" PopupPosition="Right"
TargetControlID="revmobile" HighlightCssClass="errorField"></asp:ValidatorCalloutExtender>
<asp:FilteredTextBoxExtender ID="ftemobile" runat="server" TargetControlID="txtmobile" ValidChars="0123456789"></asp:FilteredTextBoxExtender>
</td>
<td>(Not Mandatory)</td>
</tr>
</table>
<h3>Do you want to get Schedule 1 by fax for free?
<br />
If yes, please enter fax number where you want to receive your Schedule 1:
</h3>
<table>
<tr>
<td style="width:24%">Fax Number</td>
<td style="width: 1px">
<asp:TextBox ID="txtfax" runat="server" CssClass="divtxt"></asp:TextBox>
<asp:RegularExpressionValidator ID="revfax" runat="server" ControlToValidate="txtfax" SetFocusOnError="true" Display="None" ErrorMessage="Fax number must be of 10 digits"></asp:RegularExpressionValidator>
<asp:ValidatorCalloutExtender ID="vce_revfax" runat="server" PopupPosition="Right" TargetControlID="revfax" HighlightCssClass="errorField"></asp:ValidatorCalloutExtender>
<asp:FilteredTextBoxExtender ID="ftefax" runat="server" TargetControlID="txtfax" ValidChars="0123456789"></asp:FilteredTextBoxExtender>
</td>
<td>(Not Mandatory)</td>
</tr>
</table>
</div>
<div style="text-align: right; padding-top: 6px;">
<asp:Button runat="server" ID="savetxt" OnClick="savetxt_Click" Text="Save" CssClass="btn" />
</div>
</asp:Panel>
and my back end code is
protected void savetxt_Click(object sender, EventArgs e)
{
try
{
Form2290.FreeServices objFreeService = new FreeServices();
objFreeService.FormID = Convert.ToString(Session["FORM_KEY"]);
objFreeService.Mobile = txtmobile.Text.Trim();
objFreeService.Fax = txtfax.Text.Trim();
BAL_F2290 objBAL = new BAL_F2290();
objBAL.SaveFreeServices(objFreeService);
}
catch (Exception ex)
{
string a = ex.Message;
}
}
please help me

sorry guys i made mistake in modalpopupextender i have set okcontrolID="savetxt" should not be there. Just i removed and code successfully executed. Thanks guys for helping me

Related

how to show an image in image control of which image path is stored in database when user selects a value in dropdownlist in asp.net?

I have a database which is shown below in the image :
Image of database
Here is the image of the form :
Image of the Form
In this form i want to show up the image in image control of which image path is stored up in database and according to subcategory value from the drop down list when user selects it how can i do it please help ... Thank You
Guys here is the source code of my form i have added sqldatasource and bind the dropdown list with sqldatasource .........
<form method="post" enctype="multipart/form-data">
<table border="0" width="450px" height="500px" align="center" class="tableshadow">
<tr>
<td colspan="2" class="toptd" style="color: white; font-size: 24px; text-align: center;
height: 40px; background-color: #60b2e7">
Update Subcategory
</td>
</tr>
<tr>
<td class="lefttxt">
<asp:Label ID="Label1" runat="server" Text="Select Subcategory:"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Height="35px" Width="134px" DataSourceID="SqlDataSource1"
DataTextField="subcatname" DataValueField="subcatid">
<asp:ListItem Text="Select category" Value="0"></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnshow" runat="server" OnClick="btnshow_Click" Text="Show" Width="94px" />
</td>
</tr>
<tr>
<td class="lefttxt">
<asp:Label ID="Label2" runat="server" Text="Subcategory Name:"></asp:Label>
<br />
</td>
<td>
<asp:TextBox ID="txtsubcategoryname" runat="server"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtsubcategoryname"
ErrorMessage="*Please Enter the Subcategory Name" Font-Bold="True" Font-Italic="True"
Font-Size="X-Small" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="lefttxt">
<asp:Label ID="Label3" runat="server" Text="Select Category:"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DLCategory" runat="server" Height="35px" Width="146px" DataSourceID="SqlDataSource1"
DataTextField="categoryname" DataValueField="categoryname">
<asp:ListItem Text="Select category" Value="0"></asp:ListItem>
</asp:DropDownList>
<tr>
<td class="lefttxt">
<asp:Label ID="Label6" runat="server" Text="Category Name:"></asp:Label>
<br />
</td>
<td>
<asp:TextBox ID="txtcategoryname" runat="server"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtcategoryname"
ErrorMessage="*Please Enter the Category Name" Font-Bold="True" Font-Italic="True"
Font-Size="X-Small" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="lefttxt">
<asp:Label ID="Label4" runat="server" Text="Old Pic:"></asp:Label>
</td>
<td>
<input type="hidden" name="h1" value="" /><asp:Image ID="Image1" runat="server" />
</td>
</tr>
<tr>
<td class="lefttxt">
<asp:Label ID="Label5" runat="server" Text="Upload New Pic:"></asp:Label>
</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" Width="225px" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnupdate" runat="server" Text="Update" OnClick="btnupdate_Click" />
</td>
</tr>
</table>
</form>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ToursandTravelsConnectionString %>"
SelectCommand="SELECT [subcatid], [subcatname], [categoryname], [pic] FROM [subcategory]">
</asp:SqlDataSource>
Providing the 'pic' column in database holds links to the images are absolute, it also depends on how you have set the drop down list up.
You will need an OnSelectedIndexChanged for the drop down which does the following:
Selects the pic url from the database where subcategory = dropdown value or text. (this depends on how you set the drop-down list up).
With that obtained value set the pic to the one you have obtained.
You need the following, providing code would make it easier.
In you ASP file add the following to the dropdown:
OnSelectedIndexChanged="drp_SelectedIndexChanged" AutoPostBack="True"
Within code behind you need:
protected void drp_SelectedIndexChanged(object sender, EventArgs e) {
//SQL To obtain url for image based on drop down selection
//providing code makes this easier
//with return url:
Image1.ImageUrl = //returned url
}
Are you having issue in showing image in image control ? Can you right click on that container and check path in properties ?
You can use AutoPostBack as True and "OnSelectedIndexChanged" to call server function and update image control based on result.
Or you can use JQuery to show images in Div tag.
jQuery(document).ready(function(){
$("#dropdownID").change(function() {
$.ajax({
url: "SericeFunction name",
success: function(msg){
.....<bind img tag >
}
});
});
});
Thank You All of you guys especially #John for your syntax you provided thanks alot.. Below is the code :
protected void btnshow_Click(object sender, EventArgs e)
{
using (var cn = new SqlConnection(#"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\PROJECT SEM6\Online Tours and Travels\App_Data\ToursandTravels.mdf;Integrated Security=True;User Instance=True"))
using (var cmd = cn.CreateCommand())
{
cn.Open();
cmd.CommandText = "select pic from subcategory where subcatid = '"+DropDownList1.Text+"'";
cmd.Parameters.AddWithValue("#subcatid",DropDownList1.Text);
using (var reader = cmd.ExecuteReader())
{
if (reader.Read())
{
var filePath = reader.GetString(0);
// For this to work images must be stored inside the web application.
// filePath must be a relative location inside the virtual directory
// hosting the application. Depending on your environment some
// transformations might be necessary on filePath before assigning it
// to the image url.
Image1.ImageUrl =("~/"+filePath);
}
}
}

Retaining textbox text after postback event

I have 3 textBoxes in a page .One of the textBox takes the new Password from the user and according to the password entered by the user , a Label displays Password strength message.But after the message displayed by the Label , the textBox text is cleared.is there a way to retain the text? I have enabled the autopostback for the textbox since i need to use the Comparevalidator for it.
Here is the code snippet-
protected void NewPassEntered(object sender, EventArgs e)
{
if (txtPassword.Text.Length < 4)
{
lblPassStr.Visible = Visible;
lblPassStr.BackColor = System.Drawing.Color.OrangeRed;
lblPassStr.Text = "Password should have more than four characters";
txtPassword.Text = "";
}
else if ((txtPassword.Text.Length > 4) && (txtPassword.Text.Length < 6) && (txtPassword.Text.Contains("#")))
{
lblPassStr.Visible = Visible;
lblPassStr.BackColor = System.Drawing.Color.Green;
lblPassStr.Text = "Password Strength:Medium";
}
else if ((txtPassword.Text.Length > 4) && (txtPassword.Text.Length < 6))
{
lblPassStr.Visible = Visible;
lblPassStr.BackColor = System.Drawing.Color.Yellow;
lblPassStr.Text = "Password Strength:Weak";
}
else if ((txtPassword.Text.Length > 6) && (txtPassword.Text.Contains("#")))
{
lblPassStr.Visible = Visible;
lblPassStr.BackColor = System.Drawing.Color.Blue;
lblPassStr.Text = "Password Strength:Strong";
}
}
}
Is there a way to check multiple special characters efficiently?
The aspx code looks like this-:
<div style="width:400px; height:250px;border-color:GoldenRod ;border-style:solid;border-width:thin;padding:20px 50px 50px 20px; position:relative; margin:100px 100px; margin-left:344px">
<table border="0" align="center" cellpadding="0" cellspacing="0" width="350" >
<tr><td> <br /></td></tr>
<tr>
<td style="width:200px">
<span class="labeltxt"> Old Password: </span>
<br /></td></tr><tr> <td style="width:200px"> <asp:TextBox ID="txtoldpass"
runat="server" CssClass="text" TextMode="Password" Width="300px"
Height="25" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="*Enter the old password" ControlToValidate="txtoldpass" Text="*" ForeColor="Red" InitialValue="">
</asp:RequiredFieldValidator><br />
</td>
</tr>
<tr>
<td><br /></td>
</tr>
<tr>
<td style="width:200px">
<span>New Password: </span>
<br /></td></tr><tr>
<td style="width:200px">
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" CssClass="text"
Width="300px" Height="25"
ontextchanged="NewPassEntered"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Font-Italic="true" ErrorMessage="**Enter the new password!" ControlToValidate="txtPassword" Text="**" ForeColor="Red" InitialValue="">
</asp:RequiredFieldValidator>
<br /></td>
</tr>
<tr>
<td><br />
<asp:Label ID="lblPassStr" runat="server" Text="Label" Visible="False"></asp:Label></td>
</tr>
<tr>
<td style="width:200px">
<span>Confirm Password:</span>
<br /> </td></tr>
<tr>
<td style="width:200px"> <asp:TextBox ID="txtPassword1" runat="server"
TextMode="Password" CssClass="text" Width="300px" Height="25"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="***Enter the new password again!" ControlToValidate="txtPassword1" Text="***" ForeColor="Red" InitialValue="">
</asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ErrorMessage="Passwords do not Match!" ControlToCompare="txtPassword"
ControlToValidate="txtPassword1"></asp:CompareValidator>
<br /> </td>
</tr>
<tr>
<td><br /><br /></td>
</tr>
<tr>
<td>
<asp:Button runat="server" ID="btnLogin" Text="Save" Height="25px"
Width="76px" CssClass="btn" BackColor="Goldenrod" onclick="btnLogin_Click"></asp:Button><asp:HyperLink ID="HyperLink1" runat="server">Cancel</asp:HyperLink>
</td>
</tr>
</table>
</div>
<asp:ValidationSummary ID="ValidationSummary1" Font-Italic="true" font-size="Small" forecolor="Black" runat="server" />
Don't postback the whole page for just setting a Password strength label. Use Javascript for this. There will be 2 benefits of using javascript here.
1) The page will not be postback (By Postback whole page will be refreshed and just because of a single field whole page postback is not a good practice)
2) No need to maintain the state of textbox as there is no postback.
What about using EnableViewState =false ?
<asp:TextBox ID="txtoldpass" runat="server" EnableViewState ="False" CssClass="text" TextMode="Password"
Width="300px" Height="25" ></asp:TextBox>

What is the error in my Validation in asp.net application?

net application. With this application a user can add a guestconnection for a time. for this i have a button that open a modal dialog who a user can add a guest. the input must be a firstname,lastname,company and the time. i use the validation controls and a ValidationGroup. The Validationcontrols check if I forget a input but if I click on "add" the code doesn't run. I try this with a simple div but the same method:
Here is my aspx code:
<div id="add">
<div id="Div2" class="popupConfirmation" runat="server" style="width:350px; height:290px;">
<div class="bodycontrol">
<table>
<tr>
<td><asp:Label ID="Label3" runat="server" Text="Vorname"></asp:Label></td>
<td><asp:TextBox ID="TextBox1" runat="server" ValidationGroup="valid" ></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="valid" runat="server" ForeColor="red" ErrorMessage="*" ControlToValidate="TextBox1"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td><asp:Label ID="Label4" runat="server" Text="Nachname"></asp:Label></td>
<td><asp:TextBox ID="TextBox2" runat="server" ValidationGroup="valid"></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator2" ValidationGroup="valid" runat="server" ForeColor="red" ErrorMessage="*" ControlToValidate="TextBox2"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td><asp:Label ID="Label5" runat="server" Text="Firma"></asp:Label></td>
<td><asp:TextBox ID="TextBox3" runat="server" ValidationGroup="valid"></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator3" ValidationGroup="valid" runat="server" ForeColor="red" ErrorMessage="*" ControlToValidate="TextBox3"></asp:RequiredFieldValidator></td>
</tr>
</table>
<br />
<table>
<tr>
<td><asp:LinkButton ID="LinkButton1" runat="server" class="GuestButtons" Text="Hinzufügen" ValidationGroup="valid" onclick="btn_GuestListViewAddDialog_YES_Click" ></asp:LinkButton></td>
<td><asp:LinkButton ID="LinkButton2" runat="server" class="GuestButtons" Text="Abbrechen" ValidationGroup="never"></asp:LinkButton></td>
</tr>
</table>
<br />
<table>
<tr>
<td><asp:Label ID="Label10" runat="server" Text="*Bitte alle Felder ausfüllen"></asp:Label></td>
</tr>
</table>
</div>
</div>
</div>
here is my c# code:
protected void btn_GuestListViewAddDialog_YES_Click(object sender, EventArgs e)
{
if (Page.IsValid) //Here i make a breakpoit but it doesn't use this code :(
{
...//here is my code
}
}
this is in my script block if i click on the linkbutton:
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$lw_content$LinkButton1", "", true, "valid", "", false, true))
If you want to force validation on serverside you need to call Page.Validate() before you check Page.IsValid.
protected void btn_GuestListViewAddDialog_YES_Click(object sender, EventArgs e)
{
Page.Validate();
if (Page.IsValid)
{
The LinkButton must also have a ValidationGroup, the same valid-group if you want to validate this group if the link-button was clicked or a different group if you don't want to trigger validation.
Edit: However, Page.Validate should be redundant since CausesValidation is true by default for a LinkButton and you have specified also a ValidationGroup for it. So i'm at a loss.

how to set RequiredFieldValidator to validate against specific user control which has multiple instance?

so let say i have a user control which called 7 times in an aspx file, i put field validator control in that user control, the problem is everytime i click some buttons which cause postback, field validator always validate controls against all instances of my user control, what i want is to validate against specific user control, i have tried this :
<asp:TextBox runat="server" ID="DateNew" CssClass="time" Width="185px"/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Date can not be empty" ControlToValidate="DateNew" ValidationGroup='<%= ClientID %>' Text="*"> </asp:RequiredFieldValidator>
<asp:Button runat="server" ID="NewSchedule" Text="Schedule" CssClass="bgrey"
OnClientClick="CheckKeyValues()" OnClick="NewSchedule_Click" ValidationGroup='<%= ClientId %>'/>
this is not working... any correction? thanx before. btw some example would be great.
update : aspx file with a user control called 7 times
<asp:ScriptManager id="ScriptManager1" runat="server">
</asp:ScriptManager>
<div id="divError" class="n fail" style="display:none; margin:15px; width:2330px">
<h5>
The following errors were found
</h5>
<asp:ValidationSummary ID="ValidationSummary" runat="server" />
</div>
<div class="warea clearfix" style="width: 2350px">
<div style="float:left;">
<uc1:ucApplicationProgress runat="server" id="ucApplicationProgress" TestType="Interview 1" />
</div>
<div style="float:left;">
<uc1:ucApplicationProgress runat="server" id="ucApplicationProgress1" TestType="Interview 2"/>
</div>
<div style="float:left;">
<uc1:ucApplicationProgress runat="server" id="ucApplicationProgress2" TestType="Interview 3"/>
</div>
<div style="float:left;">
<uc1:ucApplicationProgress runat="server" id="ucApplicationProgress3" TestType="English Test"/>
</div>
<div style="float:left;">
<uc1:ucApplicationProgress runat="server" id="ucApplicationProgress4" TestType="Medical Examination"/>
</div>
<div style="float:left;">
<uc1:ucApplicationProgress runat="server" id="ucApplicationProgress5" TestType="Internal Psycho Test"/>
</div>
<div style="float:left;">
<uc1:ucApplicationProgress runat="server" id="ucApplicationProgress6" TestType="External Psycho Test"/>
</div>
</div>
user control file :
<h3><asp:Label runat="server" ID="TypeNew"/></h3>
<table>
<tr>
<td>Date</td>
<td>
<asp:TextBox runat="server" ID="DateNew" CssClass="time" Width="185px"/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Date can not be empty" ControlToValidate="DateNew">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Time</td>
<td>
<asp:TextBox runat="server" ID="HourNew" Width="40px"/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Time can not be empty" ControlToValidate="HourNew" Text="*">
</asp:RequiredFieldValidator>:
<asp:TextBox runat="server" ID="MinuteNew" Width="40px"/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Minute can not be empty" ControlToValidate="MinuteNew" Text="*">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Location</td>
<td>
<asp:TextBox runat="server" ID="LocationNew" TextMode="MultiLine"/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Location can not be empty" ControlToValidate="LocationNew" Text="*">
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Interviewer</td>
<td>
<asp:TextBox runat="server" ID="InterviewerNew" autocomplete="off" onchange="MarkFlag(this.id)"/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="Interviewer can not be empty" ControlToValidate="InterviewerNew" Text="*">
</asp:RequiredFieldValidator>
<asp:HiddenField runat="server" ID="InterviewerKeys"/>
<asp:HiddenField runat="server" ID="InterviewerEmail"/>
</td>
</tr>
<tr>
<td> </td>
<td><asp:Button runat="server" ID="NewSchedule" Text="Schedule" CssClass="bgrey" OnClientClick="CheckKeyValues()" OnClick="NewSchedule_Click" /></td>
</tr>
</table>
C# :
public String ValidationGroup
{
get
{
return RequiredFieldValidator1.ValidationGroup;
}
set
{
RequiredFieldValidator1.ValidationGroup = value;
RequiredFieldValidator2.ValidationGroup = value;
RequiredFieldValidator3.ValidationGroup = value;
RequiredFieldValidator4.ValidationGroup = value;
RequiredFieldValidator5.ValidationGroup = value;
NewSchedule.ValidationGroup = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
ValidationGroup = this.ID;
}
Expose a property on your Web User Control named ValidationGroup:
public String ValidationGroup
{
get { return RequiredFieldValidator1.ValidationGroup; }
set {
RequiredFieldValidator1.ValidationGroup = value;
NewSchedule.ValidationGroup = value;
}
}
Then set it to a unique value for each instance you create on your web form.
Give the validation group value anything like "Name" as i have given.
And add the same validation group to both controls on which validation is to be fired and the control whose post back should fir validation.
<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="Name"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Field value is required" ControlToValidate="TextBox1"
ValidationGroup="Name"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="Name" />
<asp:Button ID="Button2" runat="server" Text="Button" />
As in this case TextBox1 validation fires only when Button1 is clicked not on Button2 click event.

Two ModalPopupExtenders used in the same way, only one works

Within a gridview, I have an "Email" button and a "Delete" button that opens up a Modal popup window using the modalpopupextender. The problem is that the Email window opens when the button is clicked, but the Delete window does not open when its button is clicked. I am using both modalpopupextenders in the same way.
<asp:ButtonField ButtonType="Button" CommandName="Email" Text="Email" />
<asp:ButtonField ButtonType="Button" CommandName="Delete" Text="Delete" />
<%-- Email modal--%>
<asp:Panel ID="pnlPopupEmail" runat="server" Width="500px" Style="display: none">
<asp:UpdatePanel ID="updPnlEmail" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnShowEmail" runat="server" Style="display: none" />
<ajaxToolkit:ModalPopupExtender ID="mdlPopupEmail" runat="server" TargetControlID="btnShowEmail"
PopupControlID="pnlPopupEmail" CancelControlID="btnCancel" BackgroundCssClass="modalBackground" />
<div class="EmailPopup">
<table>
<tr>
<td>
To:
</td>
<td>
<asp:TextBox ID="EmailTo" runat="server" Width="350"></asp:TextBox>
</td>
</tr>
<tr>
<td>
From:
</td>
<td>
<asp:TextBox ID="EmailFrom" runat="server" Width="350"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Subject:
</td>
<td>
<asp:TextBox ID="Subject" runat="server" Width="350"></asp:TextBox>
</td>
</tr>
<tr>
<td></td>
<td> <asp:TextBox ID="EmailMessageBox" Width="350" Height="150" runat="server" TextMode="MultiLine" Wrap="true"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:LinkButton ID="SendBtn" runat="server" OnClick="SendBtn_Clicked" Text="Send" />
<asp:LinkButton ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" />
</td>
<td>
<asp:Label ID="theID" runat="server" Visible="false"></asp:Label>
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<%-- -----end email modal--%>
<%-- Start Delete Confirmation Modal --%>
<asp:Panel ID="DelConfirmPanel" runat="server" Width="500px" Style="display: none">
<asp:UpdatePanel ID="DelConfirmUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID ="TESTLabel" runat="server" Text="Are you sure?" ></asp:Label>
<asp:Button ID="DelModalButton" runat="server" Style="display: none" />
<ajaxToolkit:ModalPopupExtender ID="modalPopUpDelConfirm" runat="server" TargetControlID="DelModalButton"
PopupControlID="DelConfirmPanel" CancelControlID="DeleteCancel" BackgroundCssClass="modalBackground" />
<div class="DeletePopup">
<asp:LinkButton ID="DelConfirmedButton" runat="server" OnClick="DeleteConfirmation_Clicked"
Text="Delete" />
<asp:LinkButton ID="DeleteCancel" runat="server" Text="Cancel" CausesValidation="false" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<%-- End Delete Confirmation Modal --%>
</div>
Then in the codebehind I have a method that checks the command name and updates the updatepanel and shows the modalpopupextender.
protected void btn_Clicked(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Email")
{
// a bunch of stuff that I am leaving out but is just changing fields in the
//table withing the modal popup
updPnlEmail.Update();
mdlPopupEmail.show();
}
if (e.CommandName.Equals("Delete"))
{
int index = Convert.ToInt32(e.CommandArgument);
String id = gvReservations.DataKeys[index].Value.ToString(); // get id
try
{
DelConfirmUpdatePanel.Update();
modalPopUpDelConfirm.Show();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
Any ideas why one works and not the other? Is there a good way to debug this kind of error? Thanks a lot for any help!
Figured it out.
<asp:ButtonField ButtonType="Button" CommandName="Delete" Text="Delete" />
This is where the problem was. I didn't realize that "Delete" was a reserved command name. So when this button was clicked an exception was being thrown saying that it couldn't delete from the table. Thus, the modal popup was never being shown. I figured it out by opening the javascript console in the chrome tools.
So to fix it, I changed the command name to something else and now everything works as expected.

Categories

Resources