Open Ajax TabContainer tabs using query string in Asp.net - c#

Is it possible to open tabs of Ajax Tab Container using query string.
Something like when the query string is
localhost:81/dashboard.aspx?tab=0
localhost:81/dashboard.aspx?tab=1
localhost:81/dashboard.aspx?tab=3
My Code is
<ajax:TabContainer ID="TabContainer2" runat="server" CssClass="MyTabStyle">
<ajax:TabPanel ID="TabPanel2" runat="server" TabIndex="0">
<headertemplate>
Overview
</headertemplate>
<contenttemplate>
</contenttemplate>
</ajax:TabPanel>
<ajax:TabPanel ID="tbpnluser1" runat="server" TabIndex="1">
<headertemplate>
Overview
</headertemplate>
<contenttemplate>
</contenttemplate>
</ajax:TabPanel>
</ajax:TabContainer>
Please help

YES there is property called ActiveTabIndex
by using it you can show the tab you want in server-side
in server-side
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if(Request.QuerryString["tab"]==1)
{
tabcantainerID.ActiveTabIndex =1
}
.....
}
}
hope this will help you

Related

.NET Validators doesn't work

I have simple page Page.aspx like this:
<asp:Content ID="Content2" runat="server">
<asp:PlaceHolder ID="phNewAddress" runat="server" />
</asp:Content>
In code behind is:
protected override void Page_Load(object sender, EventArgs e)
{
AddressDetail xControl = (AddressDetail)Page.LoadControl("AddressDetail.ascx");
phNewAddress.Controls.Add(xControl);
}
AddressDetail.ascx is:
<asp:TextBox ID="address_name" runat="server" />
<asp:RequiredFieldValidator ID="rfv" runat="server"
ControlToValidate="address_name" ErorMessage="Required" ValidationGroup="save">*
</asp:RequiredFieldValidator>
<asp:DropDownList ID="address_state" runat="server" AutoPostBack="true" />
<asp:Button ID="btnSave" runat="server" Text="Save" ValidationGroup="save" OnClick="btnSave_Click" />
DropDownList address_state is binding from datasource.
Now. After page is loaded and I press Save button, validator doesn't work.
But if I change DropDownList, so fire postback, and then press Save button, validator works fine.
Can anyone help me?
I am guessing validation controls work with viewstate, Move the below code from Page_load event to Page_Init event and see if it works.
protected override void Page_Init(object sender, EventArgs e)
{
AddressDetail xControl = (AddressDetail)Page.LoadControl("AddressDetail.ascx");
phNewAddress.Controls.Add(xControl);
}

Enable tabpanel in tabcontainer

I have a tabcontainer with two tabs. The first tab contains a textbox, while the second tab contains a panel.
I want the second tab to be disabled at first page load, and I want it to become enabled as soon as the user enters an input in the textbox in tab1. When textbox in tab1 is emptied again, the second tab should again be disabled.
I tried the following code, but the second tab remains disabled no matter what.
Any help would be appreciated. Thank you!
aspx
<asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="4" HeaderText=""
Height="578px" Width="900px" TabStripPlacement="Top" ScrollBars="None" UseVerticalStripPlacement="false"
VerticalStripWidth="120px" BackColor="White" BorderColor="White" Style="margin-right: 84px">
<asp:TabPanel ID="TabPanel1" runat="server">
<HeaderTemplate>
General
</HeaderTemplate>
<ContentTemplate>
<asp:UpdatePanel ID="TestUpdatePanel" runat="server">
<ContentTemplate>
<table style="height: 247px; width: 100%;">
<tr>
<td>
<asp:TextBox ID="HorizonTextBox" runat="server" OnTextChanged="HorizonTextBox_TextChanged"
AutoPostBack="True"></asp:TextBox>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel2" runat="server">
<HeaderTemplate>
Dashboard
</HeaderTemplate>
<ContentTemplate>
<asp:Button ID="RunSimulationButton" runat="server" Text="Run Simulation" OnClick="RunSimulationButton_OnClick" />
<br />
<br />
<asp:Panel ID="PlotPanel" runat="server">
</asp:Panel>
</ContentTemplate>
</asp:TabPanel>
aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
TabContainer1.ActiveTabIndex = 0;
TabPanel2.Enabled = false;
}
}
protected void HorizonTextBox_TextChanged(object sender, EventArgs e)
{
if(HorizonTextBox.Text != "")
{
TabPanel2.Enabled = true;
}
}
you may need to enclose whole tab container into updatepanel to allow update panel enable/disable child controls

How to get DataList's ItemTemplate items Url on server

I am using Asp.Net C# 4.0. I am using DataList on a page which include ImageButton. The code is as follows;
<asp:DataList ID="DataList1" runat="server" DataSourceID="ObjectDataSource2"
DataKeyField="Pic_ID">
<HeaderTemplate>
Click Image to enlarge
</HeaderTemplate>
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" Height="110px"
ImageUrl='<%# Eval("Pic_Path") %>' Width="111px"
onclick="ImageButton1_Click(this.ToString())"/>
</ItemTemplate>
</asp:DataList>
I want to send the current ImageUrl in the ImageButton to a method "ImageButton1_Click" on server in code behind. I tried changing my code several times but could not fix it. With this code i am currently getting error which says "Method name expected". My method on server is;
protected void ImageButton1_Click(string Param)
{
//Code here
}
Saying in short, I want to send the Url of the image in DataList to server for some processing. Thanks for any help.
try below
<asp:ImageButton ID="ImageButton1" runat="server" Height="110px"
ImageUrl='<%# Eval("Pic_Path") %>' Width="111px"
onclick="ImageButton1_Click"/>
and change method as
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
var btn = sender as ImageButton;
var url = btn.ImageUrl;
}

how to get value of textbox in listview?

<asp:ListView runat="server" ID="lvAttachments" ItemPlaceholderID="ph" OnItemDataBound="lvAttachments_ItemDataBound">
<LayoutTemplate>
<asp:PlaceHolder ID="ph" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<asp:LinkButton runat="server" ID="btnReject" OnClick="btnReject_Click"></asp:LinkButton>
<asp:TextBox runat="server" ID="tbReason" CssClass="textbox" TextMode="MultiLine"></asp:TextBox>
</ItemTemplate>
</asp:ListView>
My question is: how to get text from textbox, while btnReject click action?
protected void btnReject_Click(object sender, EventArgs e)
{
LinkButton btnReject = (LinkButton)sender;
// how to get tbReason.Text from this item?
}
Regards
edit:
Problem resolved !
We just need to add in Page_Load code to prevent re-load listview and clear textboxes:)
http://forums.asp.net/t/1712482.aspx/1
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lvAttachments.DataSource = tAttachmentBO.getAttachmentsToAccept();
lvAttachments.DataBind();
}
}
Something like this should work
I'm on ipad so apologize for any mistakes
TextBox txt = (TextBox)btnReject.Parent.FindControl("tbReason")

Adding javascript to a link's OnClientClick property while binding a repeater

I'm trying to get this working but no success:
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="btnDeleteFamily_Click">
<HeaderTemplate>
<table>
<tr>
<th width="90" valign="top"><%=getTag("name")%></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("chrname")%></td>
<asp:LinkButton ID="btnDeleteFamily" CssClass="fRight ui-icon ui-icon-trash" runat="server" CommandName="delete" CommandArgument='<%#Eval("idmember")%>' OnClientClick='return confirm("<%= getTag("deletefamilymemberdialog") %>")' Text="" ValidationGroup="delete_family" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
When clicking on the btnDeleteFamily OnClientClick the confirm dialog is not shown.
getTag (method in the code behind) is used for localization to get the text depending on the language. My intention is to show that message in the JavaScript dialog, but I'm getting:
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$rptFamily$ctl01$btnDeleteFamily','')" class="fRight ui-icon ui-icon-trash" id="ctl00_ContentPlaceHolder1_rptFamily_ctl01_btnDeleteFamily" onclick='return confirm("<%= getTag("deletefamilymemberdialog") %>");'/>
So it's not processing getTag in the server side otherwise I would be getting
onclick='return confirm("Are you sure that you want to delete this entry?");'
Thanks
I think writing the message to page as a javascript variable is a better solution :
<script>
var deleteMemberDialogMessage = '<%= getTag("deletefamilymemberdialog") %>';
</script>
And your repeater :
<asp:LinkButton ID="btnDeleteFamily" CssClass="fRight ui-icon ui-icon-trash"
runat="server" CommandName="delete" CommandArgument='<%#Eval("idmember")%>'
OnClientClick='return confirm(deleteMemberDialogMessage)' Text=""
ValidationGroup="delete_family" />
By the way be sure that your deletefamilymemberdialog message doesn't have single quote.
EDIT : If you want to bind a value from your datasource to your repeater, you should bind your column to control instead of Response.Write (<%=) like that :
<asp:LinkButton ID="btnDeleteFamily" CssClass="fRight ui-icon ui-icon-trash"
runat="server" CommandName="delete" CommandArgument='<%#Eval("idmember")%>'
OnClientClick='<%# Bind("return confirm('{0}');'", "YourColumnName") %> Text=""
ValidationGroup="delete_family" />
protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
LinkButton lb = e.Item.FindControl("btnDelete") as LinkButton;
if (lb != mull) {
lb.OnClientClick = "whatever";
}
}
It seems to be ok, for me at least.
You could try it in firefox, and using the WebDeveloper toolbar or Firebug extensions you will be able to get more information about what is happening behind scene.
Maybe there are others errors on the page that doesn't allow this code to work.
If you want to use the jQuery dialog in confirmation mode to bind to link buttons on a repeater inside an update panel, AND the code you want to execute after confirmation is different for each row, you can set it up this way:
Add a javascript function to your page/control like this:
function confirm(buttonFunctionForPostBack)
{
$("#dialog").dialog('option', 'buttons', {
"Cancel": function() {
$(this).dialog("close");
},
"Delete Payment": function () {
eval(buttonFunctionForPostBack);
$(this).dialog("close");
}
}
).dialog('open');
}
And in your code behind:
public void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
LinkButton lb = e.Item.FindControl("deleteButton") as LinkButton;
if (lb != null)
{
lb.OnClientClick = "confirm(\"" + this.Page.ClientScript.GetPostBackEventReference(lb, string.Empty) + "\");return false;";
}
}
And in your aspx page:
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<HeaderTemplate>
<table>
<tr>
<th width="90" valign="top"></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("name")%></td>
<td><asp:LinkButton ID="deleteButton" runat="server" CommandName="delete" CommandArgument='<%#Eval("id")%>' Text="Delete" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
This lets you take advantage of the fact that you can set the dialog's 'buttons' option after the dialog was created. Also, it doesn't require any extra script variables.

Categories

Resources