|
Are you trying at serverside. If yes, then you can get via prperty SelectedItem.It returns null if no item is selected.
Are you looking for somthing else?
|
|
|
|
|
You can check it with SelectedIndex Properties.
if (RadioButtonList1.SelectedIndex > -1)
{
Response.Write(RadioButtonList1.SelectedIndex.ToString());
}
else
{
Response.Write("No Item Is Selected");
}
Cheers !
Abhijit Jana | MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Hello, This Is Vikash Gohil.
I need some guideline/help on the following issue.
I have a webpage with a function written on Page_load event which takes the arguments from url using querystring and prints a single line on the page after execution of the function.
Now as per my knowledge, if i need to execute that function, i need to provide the full url in the address bar of the browser along with arguments needed.
Now what i want is, I dont want my webapp to redirect to that webpage but still need the function on that page, to get executed with the dynamically passed argument values.
Now, in first place, is this thing possible?
If yes, then can someone tell me the way to do it.
if no, then can i achieve this functionality in some other way?
All i want is the user must not be redirected, but still want to execute the function on another page.
Awaiting a reply soon, any help would be highly appreciated.
Thanks in Advance.
|
|
|
|
|
Whatever code you have written in the Page_Load event of the webpage should be removed and kept in a method in some other class. You can have something like Common.cs where you can put all the methods which are to be used across the webpages.
|
|
|
|
|
Hello, danish.
Thanks for your response.
But the problem is I cannot change any code as it is not my creation, it is like a 3rd party Control so i can only use it and not change anything.
But anyway thanks for the reply.
|
|
|
|
|
|
Hello, Chetan.
Thanks for your reply.
But what I want is not hiding the actual URL from the user.
My actual requirement is to execute code written in page_load event on another page without redirecting to that page.
Is this thing possible?
Please reply.
|
|
|
|
|
Use Server.Transfer
Best Regards,
Chetan Patel
|
|
|
|
|
hi Friend's
Suppose i have one application which having session time out set as 45 min, now the scenario is suppose one user login and activate that session and close the browser without login off.
what happen to that session?
Is that session automatically terminate by garbage collection?
Or still remain active and if so then how to handle this session?
Thank's and regard's
Sasmi
|
|
|
|
|
Session will kill automatically after the defined time frame.
Parwej Ahamad
ahamad.parwej@gmail.com
|
|
|
|
|
Session is maintained on server. So you don't need to worry about session time out. If the session is active and user close the browser, the particular session will automatically goes down when it reaches to session time out.
Now, if you want to perfrom some operation on session timeout or you want to clear the data base information while user log off the application, you need to handle the Session_End Event in global.asax and you may need to trap the browser close also.
Cheers !
Abhijit
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
i have a gridview that contains a template field in my page. in this template field there is a combobox and a label. i want to change the text of the label when the combo box is changed, so when i'm trying to access this label in the selectedindexchange event it doesn't show the label name. dose any one can help me with this.
|
|
|
|
|
How are you accessing your label?
|
|
|
|
|
|
Hi,
this should work (replace ids):
protected void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList comboBox = (DropDownList)sender;
GridViewRow row = (GridViewRow)comboBox.NamingContainer;
Label myLabel = row.FindControl("myLabel");
myLabel.Text = "myText";
}
|
|
|
|
|
Hi all,
I am creating a dynamic data website.I have created two .dbml files with different tables.And i have registered in the Global.asax creating the two objects with MetaModel as model and model1.
Now i am having two pages and in one page i want to use tables related to model and in the other pages tables related to model1.
How can i do it ?
Thanks in advance.
|
|
|
|
|
Hello guys,
im trying to bind XML file into a Datagrid and editing it..
this is my XML file
<?xml version="1.0" encoding="utf-8"?>
<chores>
<day label="111" title="asdasd">
<job a="2" b="22" c="22" d="22" />
<job a="2" b="22" c="22" d="22" />
</day>
</chores>
My ASPX Page:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="EditTables.aspx.cs" Inherits="EditTables" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<style type="text/css">
.style1 { width: 100%; } </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<table class="style1">
<tr>
<td>
<br />
<br />
Edit your Products tables<br />
</td>
</tr>
<tr>
<td>
<asp:DataGrid ID="DataGrid1" runat="server" AllowPaging="True" AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="None" oncancelcommand="DataGrid1_CancelCommand" ondeletecommand="DataGrid1_DeleteCommand" oneditcommand="DataGrid1_EditCommand" onpageindexchanged="DataGrid1_PageIndexChanged" onupdatecommand="DataGrid1_UpdateCommand" AutoGenerateColumns="False" Width="890px">
<AlternatingItemStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateColumn HeaderText=" label">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "label")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtBoxTitle"
Text='<%# DataBinder.Eval(Container.DataItem, "label") %>'
runat="server" Height="21px" Width="80px"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="title">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "title")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtBoxTitle"
Text='<%# DataBinder.Eval(Container.DataItem, "title") %>'
runat="server" Height="21px" Width="80px"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="כמות">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "a")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtBoxAmount"
Text='<%# DataBinder.Eval(Container.DataItem, "a") %>'
runat="server" Height="21px" Width="80px"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="מחירון">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "b")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtBoxPrice"
Text='<%# DataBinder.Eval(Container.DataItem, "b") %>'
runat="server" Height="21px" Width="80px"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="גודל">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "c")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtBoxSize"
Text='<%# DataBinder.Eval(Container.DataItem, "c") %>'
runat="server" Height="22px" Width="80px"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="מוצר">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "d")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtBoxProduct"
Text='<%# DataBinder.Eval(Container.DataItem, "d") %>'
runat="server" Height="22px" Width="80px"/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn CancelText="Cancel" EditText="Edit" UpdateText="Update">
</asp:EditCommandColumn>
<asp:ButtonColumn CommandName="Delete" Text="Delete"></asp:ButtonColumn>
</Columns>
<EditItemStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<ItemStyle BackColor="#F7F6F3" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedItemStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
</asp:DataGrid>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblerror" runat="server" ForeColor="Maroon"></asp:Label>
</td>
</tr>
</table>
</asp:Content>
and finaly my CS code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Globalization;
using System.IO;
using System.Data;
using System.Data.OleDb;
public partial class EditTables : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!User.IsInRole("Admin"))
Server.Transfer("login.aspx");
if (!(Page.IsPostBack))
{
DataGrid1.DataSource = LoadMyData();
DataGrid1.DataBind();
}
}
protected DataSet LoadMyData()
{
string sourceXml = Server.MapPath("~/xml/chores2.xml");
if (!(File.Exists(sourceXml)))
{
return null;
}
DataSet cachedDataSet = (DataSet)Session["table"];
if (!(cachedDataSet == null))
{
return cachedDataSet;
}
DataSet dataSet = new DataSet();
try
{
dataSet.ReadXml(sourceXml);
Session["table"] = dataSet;
}
catch (Exception e)
{
lblerror.Text = e.Message;
dataSet = null;
}
return dataSet;
}
protected void DataGrid1_EditCommand(object source, DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = Convert.ToInt32(e.Item.ItemIndex);
DataGrid1.DataSource = LoadMyData();
DataGrid1.DataBind();
}
protected void DataGrid1_CancelCommand(object source, DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = -1;
DataGrid1.DataSource = LoadMyData();
DataGrid1.DataBind();
}
protected void DataGrid1_DeleteCommand(object source, DataGridCommandEventArgs e)
{
DataSet dataSet = LoadMyData();
int row = Convert.ToInt32(e.Item.ItemIndex);
dataSet.Tables[0].Rows[row].Delete();
dataSet.WriteXml(Server.MapPath("~/XML/chores2.xml"));
Session["table"] = null;
DataGrid1.EditItemIndex = -1;
DataGrid1.DataSource = LoadMyData();
DataGrid1.DataBind();
}
protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e)
{
DataSet dataSet = LoadMyData();
int row = Convert.ToInt32(e.Item.ItemIndex);
int w = Convert.ToInt32(e.Item.Attributes);
TextBox txtBoxLabel = (TextBox)e.Item.FindControl("txtBoxLabel");
dataSet.Tables[0].Rows[row]["label"] = txtBoxLabel.Text;
TextBox txtBoxTitle = (TextBox)e.Item.FindControl("txtBoxTitle");
dataSet.Tables[0].Rows[row]["title"] = txtBoxTitle.Text;
TextBox txtBoxProduct = (TextBox)e.Item.FindControl("txtBoxProduct");
dataSet.Tables[0].Rows[3]["a"] = txtBoxProduct.Text;
TextBox txtBoxSize = (TextBox)e.Item.FindControl("txtBoxSize");
dataSet.Tables[0].Rows[3]["b"] = txtBoxSize.Text;
TextBox txtBoxPrice = (TextBox)e.Item.FindControl("txtBoxPrice");
dataSet.Tables[0].Rows[3]["c"] = txtBoxPrice.Text;
TextBox txtBoxAmount = (TextBox)e.Item.FindControl("txtBoxAmount");
dataSet.Tables[0].Rows[3]["d"] = txtBoxAmount.Text;
dataSet.WriteXml(Server.MapPath("~/XML/chores2.xml"));
Session["table"] = null;
DataGrid1.EditItemIndex = -1;
DataGrid1.DataSource = LoadMyData();
DataGrid1.DataBind();
}
protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataSource = LoadMyData();
DataGrid1.DataBind();
}
}
The error i get starts in this line of code
dataSet.Tables[0].Rows[row]["a"] = txtBoxProduct.Text;
I've been told that this could be a problem in the number of Tables of the dataset, according to my XML file i should create 2 tables in DATASET.
any help please?
thank you.
|
|
|
|
|
|
|
Hey guys, am using a file uploader for a user to select a file,
But only the files in my working directory are allowed. If I
select a file outside my working directory i get an error saying:
the path of the file could not be found...I would to choose a file
from different directories
Does any know what i can do on this one?
Please help
|
|
|
|
|
Perhaps you don't have permission.
|
|
|
|
|
You need to give more information of your code, then any one can look on it
and tell you what is the problem.
|
|
|
|
|
Yes, we need detail description of your problem including code then
only we can help you in better manner.
Jinal Desai
|
|
|
|
|
Hey thanks guys for ya reps, well i wish i would xplain this better,
Here is a piece of code:
below 'files' is the name of my file uploader
HttpPostedFile myFile = files.PostedFile;
string strFilename = Path.GetFileName(myFile.FileName);
if (strFilename != "")
{
string[] lines = File.ReadAllLines(strFilename);
}
Reason: As anyone one else knows, when you choose browse on a file uploader, you can only select a file if it is present in the dialog box that opens.
So if I select a file in my working directory, it works ok but if i select a file 'Outside' my working directory then I receive the error above(file not found).
E.g my working directory is: C:\MyProject\SMS Send\contacts.txt this works
and if I choose: C:\Documents and Settings\Morgan\Desktop\testing.txt this will give a FileNotFound exception,
and when i look at this exception it is pointing to:C:\MyProject\SMS Send\testing.txt which is my working directory. I don't quiet understand why it is searching for the file from my working directory..
Please help
Thanks
Mor
|
|
|
|
|
You need to user Server.MapPath() while retrieving the full path.
e.g:
string strFilename = Server.MapPath(Path.GetFileName(myFile.FileName));//path of a file
I guess this should work now.
When you fail to plan, you are planning to fail.
|
|
|
|