I am using the ajaxtoolkit in order to make a popup where users can interact with server controls. Here is a simple implemetation:
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="Server" />
<asp:Button ID="Button1" runat="server" Text="Button" />
<ajaxToolkit:PopupControlExtender ID="PopEx" runat="server"
TargetControlID="Button1"
PopupControlID="Panel1"
Position="Center" />
<asp:Panel ID="Panel1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="AppName" DataValueField="PK_Application"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" SelectCommand="SELECT [AppName], [PK_Application] FROM [Application]"></asp:SqlDataSource>
</asp:Panel>
It appears to be working correctly, but when I press the button the panel flashes open then dissapears and I can't interact with it. How do I fix this?
The solution is to prevent the postback of the button click:
protected void Page_Load(object sender, EventArgs e)
{
Button1.Attributes.Add("onclick", "return false;");
}
Related
<asp:UpdatePanel ID="showsDatalistPanel" runat="server" Visible="false" UpdateMode="Always">
<ContentTemplate>
<div>
<asp:DropDownList ID="dateTimeFilter" CssClass="dateTimeFilterIdentifierCls" runat="server"
onclick="dateTimeFilter_SelectedIndexChanged" AutoPostBack="true" Visible="true" ClientIDMode="Static">
</asp:DropDownList>
<label id="dateTimeFilterLabel" runat="server" style="padding-left: 15px" visible="false">
בחירת מופע לפי תאריך
</label>
</div>
how can I call server side function on clicking the dropdown?
Thanks
If you really want to use click event then you have to simulate it using JS as DropDownList doesn't have build-in onclick functionality:
<asp:DropDownList ID="dateTimeFilter" CssClass="dateTimeFilterIdentifierCls" runat="server"
onclick="__doPostBack('dateTimeFilter', null);" AutoPostBack="true" Visible="true" ClientIDMode="Static">
</asp:DropDownList>
and then in your server code you have modify page load event accordingly:
protected void Page_Load(object sender, EventArgs e)
{
if(Page.IsPostBack)
{
if(Request.Params.Get("__EVENTTARGET").ToString() == dateTimeFilter.ClientID)
{
dateTimeFilter_SelectedIndexChanged(dateTimeFilter, null);
}
}
}
But I'm sill confused why you can't just use standard OnSelectedIndexChanged or OnSelectedValueChanged?
I have a captcha code in my site.
sometimes needs to chenge that picture , but i dont want the whole page refreh.
i used updatepanel in this way :
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="lblmsg" runat="server" Font-Bold="True"
ForeColor="Red" Text=""></asp:Label>
<asp:TextBox ID="txtimgcode" runat="server"></asp:TextBox>
<asp:Image ID="Image1" runat="server" ImageUrl="~/CImage.aspx" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Check" />
<asp:Button ID="Button3" runat="server" Text="refresh" OnClick="Button3_Click" />
</ContentTemplate>
</asp:UpdatePanel>
Here is Button3 code behind :
protected void Button3_Click(object sender, EventArgs e)
{
Image1.ImageUrl = "~/CImage.aspx";
}
Button1 Works correctly But Button3 which should change the captcha picture doesn't work.
Am I missing something?
In addition if Iwant to use a refresh image instead of Button3,What controls should I use?
The image likely isn't updating during partial postback because the browser doesn't realize that the image content has changed since it been targeted to same page over and over. Adding querystring might help in this case one need to pass random id as querystring to the ImageUrl of the captcha.
protected void Button3_Click(object sender, EventArgs e)
{
Image1.ImageUrl = string.Format("~/CImage.aspx?img={0}", Guid.NewGuid());
}
There is nothing wrong with your code Kindly check if "~/CImage.aspx" is returning correct values or not. I have modified your code Kindly check:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:Label ID="lblmsg" runat="server" Font-Bold="True"
ForeColor="Red" Text=""></asp:Label>
<asp:TextBox ID="txtimgcode" runat="server"></asp:TextBox>
<asp:Image Width="100" Height="100" ID="Image1" runat="server" ImageUrl="~/CImage.aspx" />
<asp:Button ID="Button1" runat="server" Text="Check" />
<asp:Button ID="Button3" OnClick="Button3_Click" runat="server" Text="refresh" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button3" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
protected void Button3_Click(object sender, EventArgs e)
{
if (Image1.ImageUrl == "Koala.jpg")
{
Image1.ImageUrl = "Close.png";
}
else
{
Image1.ImageUrl = "Koala.jpg";
}
}
im trying to get the value of a dropdownlist and insert it into a label inside an update panel like the following:
<asp:UpdatePanel ID="udpTutorialDropDown" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="TutorialSeries" DataTextField="SeriesName" DataValueField="VideoSeriesNameID" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList><br />
<asp:SqlDataSource ID="TutorialSeries" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" SelectCommand="ViewSeasonName" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<asp:Label ID="lblEpisode" runat="server" Text="Label"></asp:Label><br />
<asp:TextBox ID="tbxURL" runat="server"></asp:TextBox><br />
<asp:TextBox ID="tbxDiscription" runat="server"></asp:TextBox><br />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
and in code behind i have
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
lblEpisode.Text = DropDownList1.SelectedValue.ToString();
}
but i dont know why it doesnt update the label!! the text of the label remains the same!!! can someone spot the problem??
You have to put drop down list into existing Update panel as well...
Try to remove the trigger to get something like so
<br />
<asp:SqlDataSource ID="TutorialSeries" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" SelectCommand="ViewSeasonName" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<asp:UpdatePanel ID="udpTutorialDropDown" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="TutorialSeries" DataTextField="SeriesName" DataValueField="VideoSeriesNameID" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
<asp:Label ID="lblEpisode" runat="server" Text="Label"></asp:Label><br />
<asp:TextBox ID="tbxURL" runat="server"></asp:TextBox><br />
<asp:TextBox ID="tbxDiscription" runat="server"></asp:TextBox><br />
</ContentTemplate>
You need to call the Update() method of the update panel in your Event as shown below.
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
lblEpisode.Text = DropDownList1.SelectedValue.ToString();
udpTutorialDropDown.Update();
}
All the best!
UPDATE
You must add AutoPostBack="true" property in the drop down list. And, ignore my previous instructions. I.e. calling the Update() method of the update panel. That's required only when you have UpdateMode="Conditional"
This should work :)
I'm using Visual Studio 2010 with framework 3.5 and Ajax Control Toolkit .NET 3.5.
I working on a asp.net web forms website.
On a form I have this: a textbox, an imagebutton, a button, a calendar and a requiredfieldvalidator:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<p>
<br />
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:Label id="Label3" runat="server">Date</asp:Label>
<asp:textbox id="txtInitialDate" runat="server" Width="75px" MaxLength="10"></asp:textbox>
<asp:ImageButton ID="imgBegin"
ImageUrl="~/images/Icon1.jpeg" runat="server"
AlternateText="" Height="24px" Width="24px" />
<asp:CalendarExtender ID="CalendarExtender1" runat="server"
TargetControlID="txtInitialDate"
PopupPosition="BottomLeft" PopupButtonID="imgBegin"
>
</asp:CalendarExtender>
<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="txtInitialDate"
Display="Dynamic"></asp:requiredfieldvalidator>
<asp:button id="Button2" runat="server" Text="Send" onclick="Button2_Click"></asp:button>
</asp:Content>
code behind:
override protected void OnInit(EventArgs e)
{
Button2.Attributes.Add("onclick", "javascript:" + Button2.ClientID + ".disabled=true;" + "javascript:" + Button2.ClientID + ".value='Processing.';" + this.GetPostBackEventReference(Button2) + ";");
base.OnInit(e);
}
protected void Button2_Click(object sender, EventArgs e)
{
string a = "some_value";
}
The interaction here is that the user clicks on the ImageButton, the calendar shows, the user clicks on a date and then hits the button.
The problem:
If I run the website and click on the ImageButton first and pick a date, then when the button is clicked no events are fired.
But if I comment the code of the validator:
<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="txtInitialDate"
Display="Dynamic"></asp:requiredfieldvalidator>
Then the events are fired correctly.
I want to be able to use the requiredfieldvalidator, but I don't want it to create conflict with the button
Why is this happening and How can I solve this?
Thanks...
Use CausesValidation=False in the image button markup:
<asp:ImageButton ID="imgBegin" CausesValidation="False" ImageUrl="~/images/Icon1.jpeg" runat="server" Height="24px" Width="24px" />
You can add that javascript for Button2 in the markup also (instead of OnInit code-behind). Just use OnclientClick attribute in the Button2 mark up
I have a repeater and the items are editable through an edit button which opens a FormView in edit mode. The formView is initially invisible and the repeater visible. Once edit is pressed the repeater goes invisible then the formview becomes visible with the item to edit.
Once changes have been made the user presses update. This sets the formview invisible and the repeater visible.
The problem is the formview goes invisible but the repeater doesn't become visible. This I think is caused by the fact the formview is within an update panel and the repeater isn't? Only the items in the update panel are being altered on clicking update because it is only a partial page update.
I can't put the repeater within the update panel because there is a requirement that the public view doesn't use javascript.
Does anyone know how I could make the repeater reappear?
<asp:Repeater id="resultsRepeater" runat="server" DataSourceID="vehiclesDataSource" >
<ItemTemplate>
<asp:Label id="makeLabel" runat="server" Text='<%# Eval("Make") %>' />
<asp:Button id="editButton" runat="server" Text="Edit" CommandArgument='<%# Eval("Id") %>' OnClick="EditButton_Click" />
</ItemTemplate>
<asp:Repeater>
<asp:UpdatePanel ID="updatePanel" runat="server">
<ContentTemplate>
<asp:Panel id="insertUpdatePanel" runat="server" Visible="false">
<asp:FormView id="editformview" runat="server" DataKeyNames="Id" Datasourceid="VehiclesEditDataSource" >
<EditItemTemplate>
<uc:VehiclesEdit ID="VehiclesEdit" runat="server" />
<asp:Button id="updateButton" runat="server" OnClick="Update_Click" />
</EditItemTemplate>
</asp:FormView>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
protected void EditButton_Click(object sender, EventArgs e)
{
resultsRepeater.Visible = false;
insertUpdatePanel.Visible = true;
}
protected void Update_Click(object sender, EventArgs e)
{
resultsRepeater.Visible = true;
insertUpdatePanel.Visible = false;
}
This might help. I had a similar problem and this worked for me. I simply used ScriptManager to register the button (even iterated by row) as a postback control like this:
ScriptManager.GetCurrent(Page).RegisterPostBackControl(updateButton)
This caused a full postback and allowed me to set the visibility of a panel outside the update panel. I hope it works!
REVISED: Add a PostBackTrigger to your UpdatePanel to force a full post-back when your UpdateButton is clicked. This will hide your UpdatePanel and reveal your Repeater again. See final code below:
For more info refer to: https://stackoverflow.com/questions/2545508/how-do-i-force-full-post-back-from-a-button-within-an-updatepanel
<asp:UpdatePanel ID="updatePanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="updateButton" />
</Triggers>
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" Visible="false">
<asp:FormView ID="editformview" runat="server" DataKeyNames="Id" DataSourceID="VehiclesEditDataSource">
<EditItemTemplate>
<uc:vehiclesedit id="VehiclesEdit" runat="server" />
</EditItemTemplate>
</asp:FormView>
<asp:Button ID="updateButton" runat="server" OnClick="Update_Click" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>