I am using the jquery plugin in my pages e until now i have not any problem with it. the problem happend when i am tring using the select2 with a ascx page. More description of the problem below.
I have a aspx that i am using a component ascx to show somethings:
<%# Page Title="" Language="C#"
MaintainScrollPositionOnPostback="True" AutoEventWireup="true"
CodeBehind="Register.aspx.cs" Inherits="Organization.Register" %>
<%# Register Src="../DialogUF.ascx" TagPrefix="comp" TagName="DialogUF" %>
<asp:Content runat="server">
<asp:LinkButton ID="btnUF" runat="server" CausesValidation="False"
OnClick="btnUF_Click">aqui</asp:LinkButton>
<Comp:DialogUF ID="dlgUF" runat="server" />
</asp:Content>
In My code behind:
protected void btnUF_Click(object sender, EventArgs e)
{
dlgUF.Visible = true;
}
Mas ascx:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="DialogUF.ascx.cs"
Inherits="Organization.DialogUF" %>
...
<asp:Panel ID="pnlBody" runat="server">
<fieldset class="grid-form">
<div data-row-span="12">
<div data-field-span="6">
<asp:Label runat="server" AssociatedControlID="ddlState">UF
<span class="text-danger">(*)</span>:</asp:Label>
<asp:DropDownList ID="ddlState" runat="server"
CssClass="form-control"
OnSelectedIndexChanged="ddState_SelectedIndexChanged"
AutoPostBack="True">
</asp:DropDownList>
</div>
</div>
</fieldset>
...
<script type="text/javascript">
$(document).ready(function () {
$("#<%= ddlState.ClientID %>").select2();
});
</script>
</asp:Panel>
Image of select2 duplicated
Related
It does not create the button dynamically when I click the button a second time. It only creates the button on the first click and then not. What could it be?
public partial class _Default : Page
{
static bool enable = false;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnAgregarItems_Click(object sender, EventArgs e)
{
Button button = new Button();
button.Text = "HOLA";
PlaceHolder1.Controls.Add(button);
}
}
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Ejemplo._Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<div class="container">
<asp:Button ID="btnAgregarItems" runat="server" Text="Agregar Items" CssClass="btn btn-primary my-3" OnClick="btnAgregarItems_Click" />
<div class="row">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAgregarItems" />
</Triggers>
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server">
</asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Content>
I am trying to use Google Recaptcha on on my web pages. I keep getting an error saying
GoogleReCaptcha.GoogleReCaptcha)(System.Web.HttpRuntime.WebObjectActivator.GetService(typeof(GoogleReCaptcha.GoogleReCaptcha))));
Below is the screen shot:
Below is my aspx page code:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TryAgain.WebForm1" %>
<%# Register Assembly="GoogleReCaptcha" Namespace="GoogleReCaptcha" TagPrefix="cc1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>
<h1>Google ReCaptcha Form</h1>
<asp:TextBox ID="txt" runat="server"></asp:TextBox>
<cc1:GoogleReCaptcha ID="ctrlGoogleReCaptcha" runat="server" PublicKey="XXXX" PrivateKey="XXX" />
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
<asp:Label ID="lblStatus" runat="server" Text=""></asp:Label>
<asp:Button ID="btn" runat="server" Text="Submit" OnClick="btn_Click" />
</p>
</div>
</form>
</body>
</html>
Below is my aspx.cs file code:
protected void btn_Click(object sender, EventArgs e)
{
if (ctrlGoogleReCaptcha.Validate())
{
//submit form
lblStatus.Text = "Success";
}
else
{
lblStatus.Text = "Captcha Failed!! Please try again!!";
}
}
GoogleRecaptcha that I downloaded has properties like so:
I am struggling with this error for hours. Any help will be highly appreciated.
This question already has an answer here:
Ajax in UserControl
(1 answer)
Closed 8 years ago.
I am using CalenderExtender in my project inside in content place holder and calender extender is in a UserControl. This control is working in normal aspx-page but when i am dragging this control in ContentPlaceHolder then it is not working. Actually the Calender is not appearing in textBox below is my code which i used in my project.
ASPX:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Calender1.ascx.cs" Inherits="Facultymanagement.Calender1" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:TextBox ID="txtcalender" runat="server">
</asp:TextBox>
<asp:CalendarExtender ID="CalendarExtender1" runat="server" Format="MM/dd/yyyy"
TargetControlID="txtcalender" PopupButtonID="txtcalender"></asp:CalendarExtender>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
Codebehind:
protected void Page_Load(object sender, EventArgs e)
{
if (CalendarExtender1.SelectedDate.ToString() != "")
{
txtcalender.Text = CalendarExtender1.SelectedDate.ToString();
}
}
public string TextBox1Value
{
get
{
return txtcalender.Text;
// return Convert.ToString(Calendar.SelectedDate);
}
set { txtcalender.Text = value; }
}
}
This is the place where i am trying to access the value:
protected void Button1_Click1(object sender, EventArgs e)
{
Label1.Text = calender1.TextBox1Value.ToString();
}
You need to find control first
ContentPlaceHolder mpContentPlaceHolder1 = (ContentPlaceHolder)Master.FindControl("ContentPlacename");
if (mpContentPlaceHolder1 != null)
{
Button btn_searsh;
btn_searsh = (Button)mpContentPlaceHolder1.FindControl("main_search");
btn_searsh.CssClass += " " + "btn-primary";//to pass the rentpage class
}
I think you must doo something wrong.
The following code works:
WebUserControl1.ascx:
<%# Control Language="C#" ClassName="WebUserControl" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<script runat="server">
</script>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Image ID="Image1" runat="server" />
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1" PopupButtonID="Image1">
</cc1:CalendarExtender>
Default.aspx:
<%# Page Language="C#" %>
<%# Register Src="WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<uc1:WebUserControl ID="WebUserControl1" runat="server" />
<uc1:WebUserControl ID="WebUserControl2" runat="server" />
<uc1:WebUserControl ID="WebUserControl3" runat="server" />
<uc1:WebUserControl ID="WebUserControl4" runat="server" />
</form>
</body>
</html>
I have a very simple asp.net page and something not working as it should be.
This is the structure of my page:
<%# Page Title="" Language="C#" MasterPageFile="~/Management/page.master" AutoEventWireup="true" CodeFile="Account.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:ScriptManager runat="server"></asp:ScriptManager>
<div class="contentWrapper">
<asp:Panel runat="server" ID="MainPanel" ClientIDMode="Static" CssClass="MainPanel" OnLoad="MainPanel_Load">
..........
..........
..........
..........
..........
..........
<asp:Panel runat="server" id="PasswordHolder" CssClass="rtl" Width="100%" ClientIDMode="Static">
<asp:TextBox runat="server" ID="PasswordInput" CssClass="block" TextMode="Password" />
<asp:LinkButton runat="server" CssClass="btn ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" ID="EditBtn" OnClick="EditBtn_Click"><span class="ui-button-text">submit</span></asp:LinkButton>
</asp:Panel>
</asp:Panel>
</asp:Content>
Now: I'm entering a text in the TextBox(PasswordInput) and clicking submit.
The Server catch the event and entering EditBtn_Click function.
BUT! PasswordInput.Text is empty.
What should I do to fix that?
Server Side Code:
protected void Page_Load(object sender, EventArgs e)
{
if (currentUser() == null)
{
Response.Redirect("Login.aspx", true);
}
if (!IsPostBack)
{
ViewState["ContactsSortExpression"] = "LastName";
ViewState["ContactsSortDirection"] = "ASC";
}
}
protected void EditBtn_Click(object sender, EventArgs e)
{
if (PasswordInput.Text == currentUser().Password)
{
//Do something
}
}
My Problem was the Jquery dialog function
For an answer look here:
asp.net Textbox value is null when post bock with Jquery Dialog occured
Here's my situation. I have a web forms page, and it's getting annoying when the entire page scrolls to the top every time you click a control, so I'm trying to apply update panels to my page.
The submit button may or may not be click-able depending on whether or not the contents of individual update panels are in a proper state.
When the submit button is clicked, It can potentially affect any of the controls on the page.
I understand that I can do some of this with the <triggers> tag element of the update panel, but I don't want to have to put everything on the page into an update panel with it's own trigger, I'd rather that the submit button just reload the entire page.
For the sake of simplicity I've put together a sample project to represent my page. It has a "reset" button, to represent the "submit" button.
The Master page:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="WebApplication1.SiteMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form runat="server">
<asp:ScriptManager ID="ScriptManager" runat="server" EnablePartialRendering="true" />
<div class="page">
<div class="header">
<div class="title">
<h1>
My ASP.NET Application
</h1>
</div>
<div class="loginDisplay">
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
<AnonymousTemplate>
[ Log In ]
</AnonymousTemplate>
<LoggedInTemplate>
Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
[ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
</LoggedInTemplate>
</asp:LoginView>
</div>
<div class="clear hideSkiplink">
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
<asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
</Items>
</asp:Menu>
</div>
</div>
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</div>
<div class="clear">
</div>
</div>
<div class="footer">
</div>
</form>
</body>
</html>
The default page:
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Label runat=server Text="This lable represents things not in update panels" ID="label1"></asp:Label>
<asp:UpdatePanel ID="UpdatePanel1" runat=server>
<ContentTemplate>
<table>
<tr>
<td><asp:Button ID="button1" runat="server" OnClick="Button1_click" Text="Button 1" /></td>
<td><asp:TextBox ID="textBox1" runat="server" Text="StartText" Enabled="false" /></td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat=server>
<ContentTemplate>
<table>
<tr>
<td><asp:Button ID="button2" runat="server" OnClick="Button2_click" Text="Button 2" /></td>
<td><asp:TextBox ID="textBox2" runat="server" Text="StartText" Enabled="false" /></td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanelReset" runat=server>
<ContentTemplate>
<asp:Button ID="reset" runat="server" OnClick="Reset_click" Text="reset" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="button1" EventName="click" />
<asp:AsyncPostBackTrigger ControlID="button2" EventName="click" />
</Triggers>
</asp:UpdatePanel>
</asp:Content>
The code behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_click(object sender, EventArgs e)
{
textBox1.Enabled = !textBox1.Enabled;
reset.Enabled = !textBox1.Enabled && !textBox2.Enabled;
}
protected void Button2_click(object sender, EventArgs e)
{
textBox2.Enabled = !textBox2.Enabled;
reset.Enabled = !textBox1.Enabled && !textBox2.Enabled;
}
protected void Reset_click(object sender, EventArgs e)
{
textBox1.Text = "StartText";
textBox2.Text = "StartText";
label1.Text = "reset button clicked";
}
}
}
Just add a PostBackTrigger to the last UpdatePanel.
<asp:PostBackTrigger ControlID="reset" />