|
Dear colleges,
I have the following case:
1. web_page.aspx, using UC1.ascx
2. When this page is launched, after user does some things (selects settings), I need to launch web_page2.aspx from UC1.ascx with some parameters.
3. web_page2.aspx uses another user control (UC2.ascx), which needs the parameters passed from step 2 (from UC1.ascx).
Bottom line:
1. I need to pass parameters from UC1.ascx to web_page2.aspx.
2. The I need to pass these parameters from web_page2.aspx to UC2.ascx
I tried the following, which I know will not serve my needs:
In my UC1.ascx:
<br />
object[] constructorParameters = new object[1];<br />
<br />
constructorParameters.SetValue(SocketUserSettings, 0);<br />
<br />
List<Type> constParamTypes = new List<Type>();<br />
foreach (object constParam in constructorParameters)<br />
{<br />
constParamTypes.Add(constParam.GetType());<br />
}<br />
<br />
UserControl ctl = Page.LoadControl("UC2.ascx") as UserControl;<br />
System.Reflection.ConstructorInfo constructor = ctl.GetType().BaseType.GetConstructor(constParamTypes.ToArray());<br />
<br />
if (constructor == null)<br />
{<br />
throw new MemberAccessException("The requested constructor was not found on : " + ctl.GetType().BaseType.ToString());<br />
}<br />
else<br />
{<br />
constructor.Invoke(ctl, constructorParameters);<br />
}<br />
And inside UC2.ascx constructor I did:
<br />
public SocketConnectionList(SocketParam SocketUserSettings)<br />
{<br />
m_propertiesSet = true;<br />
m_SocketUserSettings = SocketUserSettings;<br />
Response.Redirect("SocketConnectionListPage.aspx");<br />
}<br />
The problem with this code is that launching an aspx from a user control will cause launching another instance of user control for the page launch and hence the parameters passed are not accessible for the second instance.
Please you help is appreciated.
|
|
|
|
|
Don’t you think the approach you are using is a bit complicated?
You can rather create a public property in the User Control(UC1). Set this property when you load this control on Page1. This way you already passed the information to the control.
In the second scenario, make user of hidden variables/query string to pass on the information.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Thanks, but I am still not clear.
I have the info I need in UC1.ascx already.
I need this information to be passed to web_page2.aspx (which in it's turn should pass it to UC2.ascx).
You have mentioned hidden variables, what does that means?
Do you have a simple example showing that (even pseudo would fit fine).
Thanks for the prompt reply!
|
|
|
|
|
When a User Control is loaded into a web form, it becomes part of the WebPage itself. So you need to look at it from that perspective and not from a Design time angle.
That means whatever information is available to Web Form2 can be easily accessed by UC2 too.
Hidden Variables[^]
Query Strings[^]
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
hello
What was known as "Web Control Library" for ASP.NET is no longer continued in VS2005/2008 am I right?
I think I remember I used tree control from the library some years ago...
dev
|
|
|
|
|
Hi folks
I'm just trying to complete a registration sector and for that I've done evrything except for activation email. I know the algorithm and how to do that but my problem is where I can't get a beautiful activation number. I want to write and sql query by which I can select from 3 beggining letters of name, 2 final letters of last name and month and day of registration date and ... (which are enetered in registration form) . So I can make a complicated activation code. you know what do I mean!
my problem would be solved only if you tell me how I can write and handle that sql query for selection.
Thanks alot.
Proper Prepration Prevents Poor Performance! h
|
|
|
|
|
I would use GUIDs for codes to send for activation. SQL generates them natively.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
|
by defining like below in web.config file
<personalization defaultProvider="AspNetSqlPersonalizationProvider">
<providers>
<remove name="AspNetSqlPersonalizationProvider" />
<add name="AspNetSqlPersonalizationProvider" type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider" connectionStringName="SqlServices" />
</providers>
</personalization>
we are able to save the data in sqlserver....any body please give me one example on webparts how to save the in oracle database
|
|
|
|
|
To use Oracle as your Database for personalization, you need to create a custom personalization provider for that.. see the following links for more info:
CUSTOM PERSONALIZATION
http://msdn.microsoft.com/en-us/library/aa479037.aspx
WEB PARTS ORACLE PERSONALIZATION
http://download.oracle.com/docs/html/E10928_01/OraclePersonalizationProviderClass.htm#BABCHDGI
|
|
|
|
|
Hi Friends,
I have used Ajax for paging in my application its work fine but when i click on my page at anywhere its getting a javascript error like top.screenleft is null or not an object when i debug it the error is pointing to ScriptResource.axd file. Please help me to give solution.
Thanks
|
|
|
|
|
Sounds like it's not working fine at all. All we can tell you, is to fix your code. If you want more help, consider telling us if you used AJAX, or if you used a framework that does AJAX, what your code looks like, the actual error ( i.e. the code that the debugger breaks into ) etc.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
When i generate excel in asp.net
it will generate but when i open & then saved this excel it showed
"save as type" "web page".
|
|
|
|
|
harish mehra wrote: when i open & then saved this excel it showed
"save as type" "web page
Yes. That's how web works. What is your question?
|
|
|
|
|
Hard to know exactly what you're doing from this gibberish ( it's not even a question ), but, I suspect you're failing to set the MIME type when you write your file down to the client.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Try this example. I did this in one of my project. I generated the excel after reading the values from a GridView.
STEP 1:Create a function call DownLoad() to download the excel file
private void Download()
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.ContentType = "application/vnd.xls";
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter objStringWriter = GenerateExcelBody();
Response.Write(objStringWriter.ToString());
Response.End();
}
STEP 2:Create a function called GenerateExcelBody() to generate the excel boby
private System.IO.StringWriter GenerateExcelBody()
{
System.IO.StringWriter objStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter objHtmlTextWriter = new System.Web.UI.HtmlTextWriter(objStringWriter);
string strVal =string.Empty;
for (int i = 0; i < grEims.Rows.Count; i++)
{
if (i % 2 == 0)
{
strVal += "<tr bgcolor='white'><td>" + grEims.Rows[i].Cells[0].Text + " " + grEims.Rows[i].Cells[1].Text + " " + grEims.Rows[i].Cells[2].Text.ToString() + " " + grEims.Rows[i].Cells[3].Text.ToString() + " " + grEims.Rows[i].Cells[4].Text.ToString() + " " + grEims.Rows[i].Cells[5].Text.ToString() + "</td></tr>" + Environment.NewLine;
}
else
{
strVal += "<tr bgcolor='white'><td>" + grEims.Rows[i].Cells[0].Text + " " + grEims.Rows[i].Cells[1].Text + " " + grEims.Rows[i].Cells[2].Text.ToString() + " " + grEims.Rows[i].Cells[3].Text.ToString() + " " + grEims.Rows[i].Cells[4].Text.ToString() + " " + grEims.Rows[i].Cells[5].Text.ToString() + "</td></tr>" + Environment.NewLine;
}
}
objHtmlTextWriter.WriteLine("<table width='100%'>" +
"<tr><td align=center bgcolor='#ccccff'><h4>List Of Interviews Conducted </h4></td></tr>" +
"<tr><td bgcolor='gray'><b>NO EMP NO. FIRST NAME LAST NAME RECORD RECEIVED ON INTERVIEW</b></td>" +
"</tr>" + strVal + "</table>");
return objStringWriter;
}
STEP 3: Call the Download() function from the control's event you want
e.g.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Download();
}
}
Hope this helps.
Let me know in case of any concern.
Niladri Biswas
|
|
|
|
|
It is useful for generating excel but u can see
when we open that excel and than save this excel
it displayed save as type web page.
can it display default save type as microsoft Excel?
|
|
|
|
|
How can i stop data saved twice when page is refreshed
|
|
|
|
|
|
1. Redirect your page on new location when data is successfully saved when user refresh the page it found new page refreshed which is not contains any sort of data saving code.
2. Clear all the state of controls after data saving and write state check condition before data save but I think first approach is better approach if you found any difficulty then I will send you sample code but remember if user go back to page and repeat same activity then you have to give dynamic image by that you always check random image code before saving same as in yahoo, google.
|
|
|
|
|
you just paste it below your class declaration
private bool _refreshState;
private bool _isRefresh;
public bool IsRefresh
{
get { return _isRefresh; }
}
protected override void LoadViewState(object savedState)
{
object[] allStates = (object[])savedState;
base.LoadViewState(allStates[0]);
_refreshState = (bool)allStates[1];
_isRefresh = _refreshState == (bool)Session["__ISREFRESH"];
}
protected override object SaveViewState()
{
Session["__ISREFRESH"] = _refreshState;
object[] allStates = new object[2];
allStates[0] = base.SaveViewState();
allStates[1] = !_refreshState;
return allStates;
}
and in button click
if (!IsRefresh)
{
//write your code here..
}
|
|
|
|
|
Hi All,
I am creating a job portal in asp.net2.0 and mysql as backend....
I want to create a drop down list.... which displays the list of states according to the country selected in the first dropdownlist by the user..
i have used the sqldatasource and wen i am inserting the following select query => "select statename from state where countryname=@countryname"... its not working for the mysql ... though its working very fine if i use the database as MSSQL ....
Plz help to solve this problem...
Thanks in Advance....
Regards,
Rajan Arora
|
|
|
|
|
You can copy this code from any website for example nokri.com which having all combo of this type but if you need it originally then lot of site provide complete list of same.
Code
1. Just fill all the entry into combo and Enable post back.
2. On Change of first combo fill the sate for country according to country name.
3. Then same for city
Table
CountryName, StateName, CityName
|
|
|
|
|
hi ,
I have a javascript function with 1 parameter[func(val)]
I'm trying to combine that param with some strings to get a regular expression
I tryed this:
var re = new RegExp(val + '.*')
and this:
var re = new RegExp('/' + val + '.*/')
it's not working...
|
|
|
|
|
benams wrote: it's not working...
And what does it has to do with ASP.Net? There is a better place[^](Web Development Forum) at CP for these type of questions.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|